Ignore:
Timestamp:
Jun 26, 1999, 1:34:43 PM (26 years ago)
Author:
hugh
Message:

DX 6 Version of ddraw rel files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ddraw/OS2DDRAW.CPP

    r97 r210  
    1 /* $Id: OS2DDRAW.CPP,v 1.3 1999-06-10 17:10:56 phaller Exp $ */
    2 
    3 /*
    4  * DirectDraw main class
    5  *
    6  * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
    7  *
    8  * Project Odin Software License can be found in LICENSE.TXT
    9  *
    10  */
    11 /*@Const************************************************************************
    12 *   Defined Constants                                                          *
    13 *******************************************************************************/
    14 #define WIN32SDK_NOPOSTWRAPPER
    15 
    16 /*@Header***********************************************************************
    17 *   Header Files                                                               *
    18 *******************************************************************************/
    19 #include <os2win.h>
    20 #include <dive.h>
    21 
    221#include <memory.h>
    23 #include <builtin.h>
    24 
    25 #include "no.h"
    26 #include <w_windows.h>
    27 #include <ddraw.h>
    28 #include <d3d.h>
    29 #include <Win32SDKPostWrapper.h>
    30 
    31 #include <fourcc.h>
    32 
     2
     3#define INITGUID
    334#include "os2ddraw.h"
    345#include "os2clipper.h"
    356#include "os2palette.h"
    367#include "os2surface.h"
     8#define _OS2WIN_H
     9#define FAR
    3710#include "misc.h"
    38 #include "os2util.h"
    39 
    40 
    41 /* KSO Apr 19 1999: Set correct interface.           *
    42  * (INTERFACE is used in the THIS and THIS_ macros)  */
    43 #undef  INTERFACE
    44 #define INTERFACE   IDirectDraw2
    45 
    46 
    47 
    48 DIVE_CAPS dcaps           = {0};
    49 FOURCC    fccFormats[100] = {0};        /* Color format code                 */
    50 
    51 
     11#include <winreg.h>
     12#include <winuser.h>
     13#include <winerror.h>
     14#include <builtin.h>
     15#include "cio2.h"
     16
     17// include with the videomodes we support
     18// better would be to get these modes from the card
     19// But for now we use standard VESA 2.0 modes with 70Hz
     20#include "os2ddrawmodes.h"
     21#include "os2DDWindow.h"
     22
     23#define KEY_DIRECT2 "\\Software\\Win32OS2\\Direct2"
     24#define KEY_DIRECT2DRAW "\\Software\\Win32OS2\\Direct2\\Draw"
     25
     26FOURCC  SupportedFourCCs[] = {FOURCC_LUT8,FOURCC_R565,FOURCC_RGB3,FOURCC_RGB4};
    5227//******************************************************************************
    5328//******************************************************************************
    5429OS2IDirectDraw::OS2IDirectDraw(GUID *lpGUID) :
    55        Referenced(0), lastError(DD_OK),
    56        pFrameBuffer(NULL), hwndClient(0), screenwidth(640),
    57        screenheight(480), screenbpp(8), fFullScreen(TRUE)
    58 {
    59   if(lpGUID && *lpGUID == IID_IDirect3D) {
    60       lpVtbl = (IDirectDraw2Vtbl *)&Vtbl3D;
    61       Vtbl3D.AddRef             = D3DAddRef;
    62       Vtbl3D.Release            = D3DRelease;
    63       Vtbl3D.QueryInterface     = D3DQueryInterface;
    64       Vtbl3D.Initialize         = D3DInitialize;
    65       Vtbl3D.EnumDevices        = D3DEnumDevices;
    66       Vtbl3D.CreateLight        = D3DCreateLight;
    67       Vtbl3D.CreateMaterial     = D3DCreateMaterial;
    68       Vtbl3D.CreateViewport     = D3DCreateViewport;
    69       Vtbl3D.FindDevice         = D3DFindDevice;
    70   }
    71   else {
    72       lpVtbl = &Vtbl;
    73       Vtbl.AddRef                   = DrawAddRef;
    74       Vtbl.Release                  = DrawRelease;
    75       Vtbl.QueryInterface           = DrawQueryInterface;
    76       Vtbl.Compact                  = DrawCompact;
    77       Vtbl.CreateClipper            = DrawCreateClipper;
    78       Vtbl.W32_CreatePalette        = DrawCreatePalette; //KSO Apr 19 1999: Sideeffect of the wrapping...
    79       Vtbl.CreateSurface            = DrawCreateSurface;
    80       Vtbl.DuplicateSurface         = DrawDuplicateSurface;
    81       Vtbl.EnumDisplayModes         = DrawEnumDisplayModes;
    82       Vtbl.EnumSurfaces             = DrawEnumSurfaces;
    83       Vtbl.FlipToGDISurface         = DrawFlipToGDISurface;
    84       Vtbl.GetCaps                  = DrawGetCaps;
    85       Vtbl.GetDisplayMode           = DrawGetDisplayMode;
    86       Vtbl.GetFourCCCodes           = DrawGetFourCCCodes;
    87       Vtbl.GetGDISurface            = DrawGetGDISurface;
    88       Vtbl.GetMonitorFrequency      = DrawGetMonitorFrequency;
    89       Vtbl.GetScanLine              = DrawGetScanLine;
    90       Vtbl.GetVerticalBlankStatus   = DrawGetVerticalBlankStatus;
    91       Vtbl.Initialize               = DrawInitialize;
    92       Vtbl.RestoreDisplayMode       = DrawRestoreDisplayMode;
    93       Vtbl.SetCooperativeLevel      = DrawSetCooperativeLevel;
    94 
    95       if(lpGUID && *lpGUID == IID_IDirectDraw2)
    96             *(ULONG *)&Vtbl.SetDisplayMode  = (ULONG)DrawSetDisplayMode2;
    97       else  *(ULONG *)&Vtbl.SetDisplayMode  = (ULONG)DrawSetDisplayMode;
    98 
    99       Vtbl.WaitForVerticalBlank = DrawWaitForVerticalBlank;
    100       Vtbl.GetAvailableVidMem   = DrawGetAvailableVidMem;
     30     Referenced(0), lastError(DD_OK),
     31     pFrameBuffer(NULL), hwndClient(0), screenwidth(640),
     32     screenheight(480), screenbpp(8),PrimaryExists(false)
     33
     34{
     35  HKEY  hkDirectDraw2;
     36  DWORD dwVSize, dwVType;
     37
     38  // Setup table for 3d devices
     39  Vtbl3D.AddRef         = D3DAddRef;
     40  Vtbl3D.Release        = D3DRelease;
     41  Vtbl3D.QueryInterface = D3DQueryInterface;
     42  Vtbl3D.Initialize     = D3DInitialize;
     43  Vtbl3D.EnumDevices    = D3DEnumDevices;
     44  Vtbl3D.CreateLight    = D3DCreateLight;
     45  Vtbl3D.CreateMaterial = D3DCreateMaterial;
     46  Vtbl3D.CreateViewport = D3DCreateViewport;
     47  Vtbl3D.FindDevice     = D3DFindDevice;
     48
     49  // old V2 Interface
     50  Vtbl.AddRef                 = DrawAddRef;
     51  Vtbl.Release                = DrawRelease;
     52  Vtbl.QueryInterface         = DrawQueryInterface;
     53  Vtbl.Compact                = DrawCompact;
     54  Vtbl.CreateClipper          = DrawCreateClipper;
     55  Vtbl.CreatePalette          = DrawCreatePalette;
     56  Vtbl.CreateSurface          = DrawCreateSurface;
     57  Vtbl.DuplicateSurface       = DrawDuplicateSurface;
     58  Vtbl.EnumDisplayModes       = DrawEnumDisplayModes;
     59  Vtbl.EnumSurfaces           = DrawEnumSurfaces;
     60  Vtbl.FlipToGDISurface       = DrawFlipToGDISurface;
     61  Vtbl.GetCaps                = DrawGetCaps;
     62  Vtbl.GetDisplayMode         = DrawGetDisplayMode;
     63  Vtbl.GetFourCCCodes         = DrawGetFourCCCodes;
     64  Vtbl.GetGDISurface          = DrawGetGDISurface;
     65  Vtbl.GetMonitorFrequency    = DrawGetMonitorFrequency;
     66  Vtbl.GetScanLine            = DrawGetScanLine;
     67  Vtbl.GetVerticalBlankStatus = DrawGetVerticalBlankStatus;
     68  Vtbl.Initialize             = DrawInitialize;
     69  Vtbl.RestoreDisplayMode     = DrawRestoreDisplayMode;
     70  Vtbl.SetCooperativeLevel    = DrawSetCooperativeLevel;
     71  if(lpGUID && *lpGUID == IID_IDirectDraw2)
     72    *(ULONG *)&Vtbl.SetDisplayMode = (ULONG)DrawSetDisplayMode2;
     73  else
     74    *(ULONG *)&Vtbl.SetDisplayMode = (ULONG)DrawSetDisplayMode;
     75  Vtbl.WaitForVerticalBlank   = DrawWaitForVerticalBlank;
     76  Vtbl.GetAvailableVidMem     = DrawGetAvailableVidMem;
     77
     78  // New V4 interface
     79  Vtbl4.AddRef                 = DrawAddRef;   // todo change to a DrawAddRef4 as handling this has changed
     80  Vtbl4.Release                = DrawRelease;  // see above
     81  Vtbl4.QueryInterface         = DrawQueryInterface;
     82  Vtbl4.Compact                = DrawCompact;
     83  Vtbl4.CreateClipper          = DrawCreateClipper;
     84  Vtbl4.CreateSurface          = DrawCreateSurface4;//
     85  Vtbl4.DuplicateSurface       = DrawDuplicateSurface4;//
     86  Vtbl4.EnumDisplayModes       = DrawEnumDisplayModes4;//
     87  Vtbl4.EnumSurfaces           = DrawEnumSurfaces4; //
     88  Vtbl4.FlipToGDISurface       = DrawFlipToGDISurface;
     89  Vtbl4.GetCaps                = DrawGetCaps;
     90  Vtbl4.GetDisplayMode         = DrawGetDisplayMode4;//
     91  Vtbl4.GetFourCCCodes         = DrawGetFourCCCodes;
     92  Vtbl4.GetGDISurface          = DrawGetGDISurface4;//
     93  Vtbl4.GetMonitorFrequency    = DrawGetMonitorFrequency;
     94  Vtbl4.GetScanLine            = DrawGetScanLine;
     95  Vtbl4.GetVerticalBlankStatus = DrawGetVerticalBlankStatus;
     96  Vtbl4.Initialize             = DrawInitialize;
     97  Vtbl4.RestoreDisplayMode     = DrawRestoreDisplayMode;
     98  Vtbl4.SetCooperativeLevel    = DrawSetCooperativeLevel;
     99  Vtbl4.SetDisplayMode         = DrawSetDisplayMode2;
     100  Vtbl4.WaitForVerticalBlank   = DrawWaitForVerticalBlank;
     101  Vtbl4.GetAvailableVidMem     = DrawGetAvailableVidMem4;
     102  Vtbl4.GetSurfaceFromDC       = DrawGetSurfaceFromDC;
     103  Vtbl4.RestoreAllSurfaces     = DrawRestoreAllSurfaces;
     104  Vtbl4.TestCooperativeLevel   = DrawTestCooperativeLevel;
     105  Vtbl4.GetDeviceIdentifier    = DrawGetDeviceIdentifier;
     106
     107  if(lpGUID && *lpGUID == IID_IDirect3D)
     108  {
     109    WriteLog("D3D Interface\n");
     110
     111    lpVtbl = (IDirectDraw4Vtbl *)&Vtbl3D;
     112  }
     113  else
     114  {
     115    if(lpGUID && *lpGUID == IID_IDirectDraw4)
     116    {
     117      WriteLog("V4 Interface\n");
     118      lpVtbl = &Vtbl4;
     119    }
     120    else
     121    {
     122      WriteLog("<V4 Interface\n");
     123      lpVtbl = (IDirectDraw4Vtbl *) &Vtbl;
     124    }
    101125  }
    102126
    103127  ULONG rc = DiveOpen(&hDive, FALSE, &pFrameBuffer);
    104   if(rc) {
    105     dprintf(("ERROR: DiveOpen returned %d\n", rc));
     128  if(rc)
     129  {
     130    WriteLog("ERROR: DiveOpen returned %d\n", rc);
    106131    lastError = DDERR_GENERIC;
    107132    hDive     = NULL;
    108133  }
    109   dcaps.pFormatData    = fccFormats;
    110   dcaps.ulFormatLength = sizeof(fccFormats);
    111   dcaps.ulStructLen    = sizeof(dcaps);
    112   DiveQueryCaps(&dcaps, DIVE_BUFFER_SCREEN);
     134  else
     135  {
     136    rc = DiveQueryCaps(&dCaps,DIVE_BUFFER_SCREEN);
     137  }
     138
     139  // Shall we run in FS mode ?
     140  if(ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,KEY_DIRECT2DRAW,&hkDirectDraw2))
     141  {
     142    dwVSize = 4;
     143    dwVType = REG_DWORD;
     144    if(ERROR_SUCCESS!=RegQueryValueExA(hkDirectDraw2,"Fullscreen",NULL,&dwVType,(LPBYTE)&bScale,&dwVSize))
     145      bScale = FALSE;
     146  }
     147  else
     148    bScale = FALSE;
    113149}
    114150//******************************************************************************
     
    117153{
    118154  dprintf(("OS2IDirectDraw::~OS2IDirectDraw()\n"));
    119   if(hDive) DiveClose(hDive);
    120 }
    121 //******************************************************************************
    122 //******************************************************************************
    123 HRESULT __stdcall DrawQueryInterface(THIS, REFIID riid, LPVOID FAR * ppvObj)
    124 {
    125 #ifdef DEBUG
    126   WriteLog("OS2IDirectDraw::QueryInterface\n");
    127 #endif
     155  if(hDive)
     156    DiveClose(hDive);
     157}
     158//******************************************************************************
     159//******************************************************************************
     160FOURCC OS2IDirectDraw::GetScreenFourCC()
     161{
     162  return SupportedFourCCs[screenbpp>>3];
     163}
     164//******************************************************************************
     165//******************************************************************************
     166HRESULT __stdcall DrawQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
     167{
     168 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
     169  #ifdef DEBUG
     170    WriteLog("OS2IDirectDraw::QueryInterface\n");
     171  #endif
     172
    128173  *ppvObj = NULL;
    129174
    130175  if(!IsEqualGUID(riid, CLSID_DirectDraw) &&
    131176     !IsEqualGUID(riid, IID_IDirectDraw) &&
    132      !IsEqualGUID(riid, IID_IDirectDraw2))
     177     !IsEqualGUID(riid, IID_IDirectDraw2) &&
     178     !IsEqualGUID(riid, IID_IDirectDraw4))
    133179//&& !IsEqualGUID(riid, IID_IUnknown))
    134     return E_NOINTERFACE;
    135 
     180  return E_NOINTERFACE;
     181
     182  // ToDo Better way of returning differnent intterfaces for same class
     183
     184  if(IsEqualGUID(riid, IID_IDirectDraw4))
     185  {
     186    WriteLog("IID_IDirectDraw4 Interface\n");
     187    me->lpVtbl = &me->Vtbl4;
     188  }
     189  else
     190  {
     191    WriteLog("No IID_IDirectDraw4 Interface\n");
     192    me->lpVtbl = (IDirectDraw4Vtbl *) &me->Vtbl;
     193  }
    136194  *ppvObj = This;
    137 
    138195  DrawAddRef(This);
    139196  return(DD_OK);
     
    141198//******************************************************************************
    142199//******************************************************************************
    143 ULONG __stdcall DrawAddRef(THIS)
     200ULONG __stdcall DrawAddRef(THIS This)
    144201{
    145202 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
    146203
    147 #ifdef DEBUG
    148   WriteLog("OS2IDirectDraw::AddRef %d\n", me->Referenced+1);
    149 #endif
     204  #ifdef DEBUG
     205    WriteLog("OS2IDirectDraw::AddRef %d\n", me->Referenced+1);
     206  #endif
     207
    150208  return ++me->Referenced;
    151209}
    152210//******************************************************************************
    153211//******************************************************************************
    154 ULONG __stdcall DrawRelease(THIS)
     212ULONG __stdcall DrawRelease(THIS This)
    155213{
    156214 OS2IDirectDraw *me = (OS2IDirectDraw *)This;
    157215
    158 #ifdef DEBUG
    159   WriteLog("OS2IDirectDraw::Release %d\n", me->Referenced-1);
    160   WriteLog("OS2IDirectDraw::%X \n", me);
    161 #endif
    162   if(me->Referenced) {
    163         me->Referenced--;
    164         if(me->Referenced == 0) {
    165             delete me;
    166             return(0);
    167         }
    168         else    return me->Referenced;
    169   }
    170   else  return(0);
     216  #ifdef DEBUG
     217    WriteLog("OS2IDirectDraw::Release %d\n", me->Referenced-1);
     218    WriteLog("OS2IDirectDraw::%X \n", me);
     219  #endif
     220
     221  if(me->Referenced)
     222  {
     223
     224    me->Referenced--;
     225    if(me->Referenced == 0)
     226    {
     227      delete me;
     228      return(0);
     229    }
     230    else
     231      return me->Referenced;
     232  }
     233  else
     234    return(0);
    171235}
    172236//******************************************************************************
     
    174238HRESULT __stdcall DrawCompact(THIS)
    175239{
    176 #ifdef DEBUG
    177   WriteLog("Compact\n");
    178 #endif
    179   return(DD_OK);
    180 }
    181 //******************************************************************************
    182 //******************************************************************************
    183 HRESULT __stdcall DrawCreateClipper(THIS, DWORD, LPDIRECTDRAWCLIPPER FAR *lplpDD, IUnknown FAR * )
     240  #ifdef DEBUG
     241    WriteLog("Compact\n");
     242  #endif
     243
     244  return(DD_OK);
     245}
     246//******************************************************************************
     247//******************************************************************************
     248HRESULT __stdcall DrawCreateClipper(THIS This, DWORD, LPDIRECTDRAWCLIPPER FAR *lplpDD, IUnknown FAR * )
    184249{
    185250 OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     
    187252 HRESULT                rc;
    188253
    189 #ifdef DEBUG
    190   WriteLog("CreateClipper\n");
    191 #endif
    192   if(newclip == NULL)   return(DDERR_OUTOFMEMORY);
     254  #ifdef DEBUG
     255    WriteLog("CreateClipper\n");
     256  #endif
     257
     258  if(newclip == NULL)
     259    return(DDERR_OUTOFMEMORY);
    193260
    194261  newclip->Vtbl.AddRef((IDirectDrawClipper *)newclip);
    195262  rc = newclip->GetLastError();
    196   if(rc != DD_OK) {
    197         *lplpDD = NULL;
    198         delete newclip;
    199   }
    200   else  *lplpDD = (IDirectDrawClipper *)newclip;
     263  if(rc != DD_OK)
     264  {
     265    *lplpDD = NULL;
     266    delete newclip;
     267  }
     268  else
     269    *lplpDD = (IDirectDrawClipper *)newclip;
    201270
    202271  return(rc);
     
    204273//******************************************************************************
    205274//******************************************************************************
    206 HRESULT __stdcall DrawCreatePalette(THIS, DWORD dwFlags,
    207                     W32_LPPALETTEENTRY lpColorTable,
    208                     LPDIRECTDRAWPALETTE FAR *lplpDD,
    209                     IUnknown FAR *pUnkOuter)
    210 {
    211  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
    212  OS2IDirectDrawPalette *newpal;
    213  HRESULT                rc;
    214  int                    palsize = 0;
    215 
    216   if(dwFlags & (DDPCAPS_2BIT | DDPCAPS_4BIT) && !(dwFlags & DDPCAPS_8BITENTRIES)) {
    217     //only support 8 bits color palettes...
     275HRESULT __stdcall DrawCreatePalette(THIS This, DWORD dwFlags,
     276            LPPALETTEENTRY lpColorTable,
     277            LPDIRECTDRAWPALETTE FAR *lplpDD,
     278            IUnknown FAR *pUnkOuter)
     279{
     280  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     281  OS2IDirectDrawPalette *newpal;
     282  HRESULT                rc;
     283  int                    palsize = 0;
     284
     285  if(dwFlags & DDPCAPS_8BITENTRIES)
     286  {
     287    // We Don't support Indexed palettes...
     288
    218289    return DDERR_INVALIDPARAMS;
    219290  }
    220   if(dwFlags & DDPCAPS_2BIT)     palsize = 4;
    221   if(dwFlags & DDPCAPS_4BIT)     palsize = 16;
    222   if(dwFlags & DDPCAPS_8BIT)     palsize = 256;
    223   if(dwFlags & DDPCAPS_ALLOW256) palsize = 256;
    224   if(palsize == 0)  return DDERR_INVALIDPARAMS;
    225 
    226   dprintf(("CreatePalette with %d colors\n", palsize));
    227 
    228   newpal = new OS2IDirectDrawPalette(me, palsize, lpColorTable);
    229   if(newpal == NULL)    return(DDERR_OUTOFMEMORY);
     291
     292  if(dwFlags & DDPCAPS_2BIT)
     293    palsize = 4;
     294  if(dwFlags & DDPCAPS_4BIT)
     295    palsize = 16;
     296  if(dwFlags & DDPCAPS_8BIT)
     297    palsize = 256;
     298  if(dwFlags & DDPCAPS_ALLOW256)
     299    palsize = 256;
     300
     301  if(palsize == 0)
     302    return DDERR_INVALIDPARAMS;
     303
     304  #ifdef DEBUG
     305    WriteLog("CreatePalette with %d colors\n", palsize);
     306  #endif
     307
     308  newpal = new OS2IDirectDrawPalette(me, palsize, lpColorTable, dwFlags);
     309  if(newpal == NULL)
     310    return(DDERR_OUTOFMEMORY);
    230311
    231312  newpal->Vtbl.AddRef((IDirectDrawPalette *)newpal);
    232313  rc = newpal->GetLastError();
    233   if(rc != DD_OK) {
    234         *lplpDD = NULL;
    235         delete newpal;
    236   }
    237   else  *lplpDD = (IDirectDrawPalette *)newpal;
     314  if(rc != DD_OK)
     315  {
     316    *lplpDD = NULL;
     317    delete newpal;
     318  }
     319  else
     320    *lplpDD = (IDirectDrawPalette *)newpal;
    238321
    239322  return(rc);
     
    241324//******************************************************************************
    242325//******************************************************************************
    243 HRESULT __stdcall DrawCreateSurface(THIS, LPDDSURFACEDESC lpDDSurfaceDesc,
    244                     LPDIRECTDRAWSURFACE FAR *lplpDD,
    245                     IUnknown FAR *pUnkOuter)
     326HRESULT __stdcall DrawCreateSurface(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc,
     327            LPDIRECTDRAWSURFACE FAR *lplpDD,
     328            IUnknown FAR *pUnkOuter)
    246329{
    247330 OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     
    249332 HRESULT                rc;
    250333
     334  #ifdef DEBUG
     335    WriteLog("CreateSurface\n");
     336    WriteLog("dwSize %d\n", lpDDSurfaceDesc->dwSize);
     337    WriteLog("dwFlags %X\n", lpDDSurfaceDesc->dwFlags);
     338    WriteLog("dwHeight %d\n", lpDDSurfaceDesc->dwHeight);
     339    WriteLog("dwWidth %d\n", lpDDSurfaceDesc->dwWidth);
     340    WriteLog("lPitch %d\n", lpDDSurfaceDesc->lPitch);
     341    WriteLog("dwBackBufferCount %d\n", lpDDSurfaceDesc->dwBackBufferCount);
     342    WriteLog("dwMipMapCount %d\n", lpDDSurfaceDesc->dwMipMapCount);
     343    WriteLog("dwAlphaBitDepth %d\n", lpDDSurfaceDesc->dwAlphaBitDepth);
     344    WriteLog("ddsCaps.dwCaps %X\n", lpDDSurfaceDesc->ddsCaps.dwCaps);
     345  #endif
     346
     347  newsurf = new OS2IDirectDrawSurface(me, (LPDDSURFACEDESC2)lpDDSurfaceDesc);
     348
     349  if(newsurf == NULL)
     350    return(DDERR_OUTOFMEMORY);
     351
     352  newsurf->Vtbl.AddRef((IDirectDrawSurface *)newsurf);
     353  rc = newsurf->GetLastError();
     354  if(rc != DD_OK)
     355  {
     356    WriteLog("Error createing Surface");
     357    *lplpDD = NULL;
     358    delete newsurf;
     359  }
     360  else
     361    *lplpDD = (IDirectDrawSurface *)newsurf;
     362
     363  return(rc);
     364}
     365//******************************************************************************
     366//******************************************************************************
     367HRESULT __stdcall DrawCreateSurface4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
     368            LPDIRECTDRAWSURFACE4 FAR *lplpDD,
     369            IUnknown FAR *pUnkOuter)
     370{
     371 OS2IDirectDraw         *me = (OS2IDirectDraw *)This;
     372 OS2IDirectDrawSurface *newsurf;
     373 HRESULT                rc;
     374
    251375#ifdef DEBUG
    252   WriteLog("CreateSurface\n");
    253   WriteLog("  dwSize %d\n", lpDDSurfaceDesc->dwSize);
    254   WriteLog("  dwFlags %X\n", lpDDSurfaceDesc->dwFlags);
    255   WriteLog("  dwHeight %d\n", lpDDSurfaceDesc->dwHeight);
    256   WriteLog("  dwWidth %d\n", lpDDSurfaceDesc->dwWidth);
    257   WriteLog("  lPitch %d\n", lpDDSurfaceDesc->lPitch);
    258   WriteLog("  lpSurface %d\n", lpDDSurfaceDesc->lpSurface);
    259   WriteLog("  dwBackBufferCount %d\n", lpDDSurfaceDesc->dwBackBufferCount);
    260   WriteLog("  dwMipMapCount %d\n", lpDDSurfaceDesc->dwMipMapCount);
    261   WriteLog("  dwAlphaBitDepth %d\n", lpDDSurfaceDesc->dwAlphaBitDepth);
    262   WriteLog("  ddsCaps.dwCaps %X\n", lpDDSurfaceDesc->ddsCaps.dwCaps);
     376  WriteLog("CreateSurface4\n");
     377  WriteLog("dwSize %d\n", lpDDSurfaceDesc2->dwSize);
     378  WriteLog("dwHeight %d\n", lpDDSurfaceDesc2->dwHeight);
     379  WriteLog("dwWidth %d\n", lpDDSurfaceDesc2->dwWidth);
     380  WriteLog("lPitch %d\n", lpDDSurfaceDesc2->lPitch);
     381  WriteLog("dwBackBufferCount %d\n", lpDDSurfaceDesc2->dwBackBufferCount);
     382  WriteLog("dwMipMapCount %d\n", lpDDSurfaceDesc2->dwMipMapCount);
     383  WriteLog("dwAlphaBitDepth %d\n", lpDDSurfaceDesc2->dwAlphaBitDepth);
     384  WriteLog("ddsCaps.dwCaps %X\n", lpDDSurfaceDesc2->ddsCaps.dwCaps);
    263385#endif
    264386
    265   newsurf = new OS2IDirectDrawSurface(me, lpDDSurfaceDesc);
    266   if(newsurf == NULL)   return(DDERR_OUTOFMEMORY);
    267 
    268   newsurf->Vtbl.AddRef((IDirectDrawSurface2 *)newsurf);
     387  newsurf = new OS2IDirectDrawSurface(me, lpDDSurfaceDesc2);
     388
     389  if(newsurf == NULL)
     390    return(DDERR_OUTOFMEMORY);
     391
     392  newsurf->Vtbl.AddRef((IDirectDrawSurface *)newsurf);
    269393  rc = newsurf->GetLastError();
    270   if(rc != DD_OK) {
    271         *lplpDD = NULL;
    272         delete newsurf;
    273   }
    274   else  *lplpDD = (IDirectDrawSurface *)newsurf;
     394  if(rc != DD_OK)
     395  {
     396    WriteLog("Error createing Surface");
     397    *lplpDD = NULL;
     398    delete newsurf;
     399  }
     400  else
     401    *lplpDD = (IDirectDrawSurface4 *)newsurf;
    275402
    276403  return(rc);
     
    280407HRESULT __stdcall DrawDuplicateSurface(THIS, LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * )
    281408{
     409  #ifdef DEBUG
     410    WriteLog("DuplicateSurface\n");
     411  #endif
     412  return(DD_OK);
     413}
     414//******************************************************************************
     415//******************************************************************************
     416HRESULT __stdcall DrawDuplicateSurface4(THIS, LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4 FAR * )
     417{
     418  #ifdef DEBUG
     419    WriteLog("DuplicateSurface\n");
     420  #endif
     421
     422  return(DD_OK);
     423}
     424//******************************************************************************
     425//******************************************************************************
     426HRESULT __stdcall DrawEnumDisplayModes(THIS This, DWORD dwFlags, LPDDSURFACEDESC lpDDSurfaceDesc,
     427                                       LPVOID lpContext, LPDDENUMMODESCALLBACK lpDDEnumModesCallback)
     428{
     429  int iMode = 0;
     430  DDSURFACEDESC DDSurfAct;
     431  BOOL fCallAgain;
     432  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     433
     434  #ifdef DEBUG
     435    WriteLog("EnumDisplayModes\n");
     436  #endif
     437
     438  // Check for Pointer to callback function
     439  if (NULL == lpDDEnumModesCallback)
     440  {
     441    #ifdef DEBUG
     442      WriteLog("EnumDisplayModes : Error NO EnumFunction passed in\n");
     443    #endif
     444
     445    return(DDERR_GENERIC);
     446  }
     447
     448
     449  // Setting up the surface
     450  // During enum we report resolution and bitdepth, maybe we should
     451  // also report back : Caps and Pitch
     452  memset(&DDSurfAct,0,sizeof(DDSURFACEDESC));
     453  DDSurfAct.dwSize = sizeof(DDSURFACEDESC);
     454  DDSurfAct.dwFlags = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT ;
     455  // Only report the bitdepth hope this is ok this way, we must set the BitMask fields
     456
     457  DDSurfAct.ddpfPixelFormat.dwSize  = sizeof (DDPIXELFORMAT);
     458  DDSurfAct.ddpfPixelFormat.dwFlags = DDPF_RGB;
     459  // Check if we use DIVE or Voodoo
     460  if(me->lpVtbl != (IDirectDraw4Vtbl *) &(me->Vtbl3D))
     461  {
     462    // DIVE modes
     463
     464    // Enumerate all modes ?
     465    if (NULL==lpDDSurfaceDesc)
     466    {
     467      // Check if we shall report 320x200 mode
     468
     469      if(dwFlags && DDEDM_STANDARDVGAMODES)
     470      {
     471        DDSurfAct.dwHeight = ModesDive[0].iYRes;
     472        DDSurfAct.dwWidth  = ModesDive[0].iXRes;
     473        DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[0].iBits;
     474        if(!lpDDEnumModesCallback(&DDSurfAct,lpContext))
     475          return (DD_OK);
     476      }
     477      // Don't know the flag for Mode X so we skip reporting it
     478
     479      // Now report all our modes
     480      iMode = 2;
     481      fCallAgain = TRUE;
     482      do
     483      {
     484        // if the mode fits in the current resolution report it
     485        // Change this if we support Fullscreen later !!!
     486        if(ModesDive[iMode].iXRes < me->dCaps.ulHorizontalResolution)
     487        {
     488          DDSurfAct.dwHeight = ModesDive[iMode].iYRes;
     489          DDSurfAct.dwWidth  = ModesDive[iMode].iXRes;
     490          DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[iMode].iBits;
     491          switch(ModesDive[iMode].iBits)
     492          {
     493            case 16:
     494              // VESA uses 565 encoding in 16 bit modes
     495              lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800;
     496              lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000007E0;
     497              lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F;
     498              break;
     499            case 24:
     500              // VESA uses per default RGB4
     501              lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     502              lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     503              lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF;
     504              break;
     505            default:
     506              break;
     507          }
     508          fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
     509        }
     510        iMode++;
     511      }
     512      while((ModesDive[iMode].iBits <= me->dCaps.ulDepth) &&
     513            (iMode < NUM_MODES_DIVE) && (TRUE==fCallAgain));
     514    }
     515    else
     516    {
     517      // No, so filter modes with lpDDSurfaceDesc
     518
     519      // Return Error if the program want to use other than the 3 supported values
     520      // for filtering
     521
     522      if (lpDDSurfaceDesc->dwFlags & !(DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT))
     523        return(DDERR_INVALIDPARAMS);
     524
     525      iMode = 0;
     526      if( (dwFlags && DDEDM_STANDARDVGAMODES) &&
     527         (
     528          (((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)&&
     529            (ModesDive[iMode].iXRes==lpDDSurfaceDesc->dwWidth)
     530           )||(!(lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)))&&
     531          (((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)&&
     532            (ModesDive[iMode].iYRes==lpDDSurfaceDesc->dwHeight))||
     533           (!(lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)))&&
     534          (((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) &&
     535            (ModesDive[iMode].iBits==lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount))||
     536           (!(lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)))
     537         )
     538        )
     539      {
     540        DDSurfAct.dwHeight = ModesDive[0].iYRes;
     541        DDSurfAct.dwWidth  = ModesDive[0].iXRes;
     542        DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[0].iBits;
     543        if(!lpDDEnumModesCallback(&DDSurfAct,lpContext))
     544          return (DD_OK);
     545      }
     546      // Don't know the flag for Mode X so we skip reporting it
     547
     548      // Now report all our modes
     549      iMode = 2;
     550      fCallAgain = TRUE;
     551      do
     552      {
     553        // if the mode fits in the current resolution and the filter applies report it
     554        // Change this if we support Fullscreen later !!!
     555        if( (ModesDive[iMode].iXRes < me->dCaps.ulHorizontalResolution)&&
     556           (
     557            (((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)&&
     558              (ModesDive[iMode].iXRes==lpDDSurfaceDesc->dwWidth))||
     559             (!(lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)))&&
     560            (((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)&&
     561              (ModesDive[iMode].iYRes==lpDDSurfaceDesc->dwHeight))||
     562             (!(lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)))&&
     563            (((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) &&
     564              (ModesDive[iMode].iBits==lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount))||
     565             (!(lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)))
     566           )
     567          )
     568        {
     569          DDSurfAct.dwHeight = ModesDive[iMode].iYRes;
     570          DDSurfAct.dwWidth  = ModesDive[iMode].iXRes;
     571          DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesDive[iMode].iBits;
     572
     573          fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
     574        }
     575        iMode++;
     576      }
     577      while((ModesDive[iMode].iBits <= me->dCaps.ulDepth) &&
     578            (iMode < NUM_MODES_DIVE) && (TRUE==fCallAgain));
     579
     580    }
     581  }
     582  else
     583  {
     584
     585    // VOODOO modes
     586
     587    // Enumerate all modes ?
     588    if (NULL==lpDDSurfaceDesc)
     589    {
     590
     591      // report all our modes
     592      iMode = 0;
     593      fCallAgain = TRUE;
     594      do
     595      {
     596        DDSurfAct.dwHeight = ModesVoodoo[iMode].iYRes;
     597        DDSurfAct.dwWidth  = ModesVoodoo[iMode].iXRes;
     598        DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesVoodoo[iMode].iBits;
     599
     600        fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
     601        iMode++;
     602      }
     603      while((iMode < NUM_MODES_VOODOO) && (TRUE==fCallAgain));
     604    }
     605    else
     606    {
     607      // No, so filter modes with lpDDSurfaceDesc
     608
     609      // Return Error if the program want to use other than the 3 supported values
     610      // for filtering
     611
     612      if (lpDDSurfaceDesc->dwFlags & !(DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT))
     613        return(DDERR_INVALIDPARAMS);
     614
     615      iMode = 2;
     616      fCallAgain = TRUE;
     617      do
     618      {
     619        // if the mode fits the filter applies report it
     620        if(
     621            (((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)&&
     622              (ModesVoodoo[iMode].iXRes==lpDDSurfaceDesc->dwWidth))||
     623             (!(lpDDSurfaceDesc->dwFlags & DDSD_WIDTH)))&&
     624            (((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)&&
     625              (ModesVoodoo[iMode].iYRes==lpDDSurfaceDesc->dwHeight))||
     626             (!(lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT)))&&
     627            (((lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT) &&
     628              (ModesVoodoo[iMode].iBits==lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount))||
     629             (!(lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT)))
     630          )
     631        {
     632          DDSurfAct.dwHeight = ModesVoodoo[iMode].iYRes;
     633          DDSurfAct.dwWidth  = ModesVoodoo[iMode].iXRes;
     634          DDSurfAct.ddpfPixelFormat.dwRGBBitCount = ModesVoodoo[iMode].iBits;
     635
     636          fCallAgain = lpDDEnumModesCallback(&DDSurfAct,lpContext);
     637        }
     638        iMode++;
     639      }
     640      while((iMode < NUM_MODES_VOODOO) && (TRUE==fCallAgain));
     641
     642    }
     643
     644  }
     645
     646  return(DD_OK);
     647}
     648//******************************************************************************
     649//******************************************************************************
     650HRESULT __stdcall DrawEnumDisplayModes4(THIS This, DWORD dwFlags, LPDDSURFACEDESC2 lpDDSurfaceDesc2,
     651                                       LPVOID lpContext, LPDDENUMMODESCALLBACK2 lpDDEnumModesCallback2)
     652{
     653  int iMode = 0;
     654  DDSURFACEDESC DDSurfAct;
     655  BOOL fCallAgain;
     656  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     657
     658  #ifdef DEBUG
     659    WriteLog("EnumDisplayModes4\n");
     660  #endif
     661  return(DD_OK);
     662}
     663//******************************************************************************
     664//******************************************************************************
     665HRESULT __stdcall DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK )
     666{
     667  #ifdef DEBUG
     668    WriteLog("EnumSurfaces\n");
     669  #endif
     670
     671  return(DD_OK);
     672}
     673//******************************************************************************
     674//******************************************************************************
     675HRESULT __stdcall DrawEnumSurfaces4(THIS, DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 )
     676{
     677  #ifdef DEBUG
     678    WriteLog("EnumSurfaces4\n");
     679  #endif
     680
     681  return(DD_OK);
     682}
     683//******************************************************************************
     684//******************************************************************************
     685HRESULT __stdcall DrawFlipToGDISurface(THIS)
     686{
     687  #ifdef DEBUG
     688    WriteLog("FlipToGDISurface\n");
     689  #endif
     690
     691  return(DD_OK);
     692}
     693//******************************************************************************
     694//******************************************************************************
     695HRESULT __stdcall DrawGetCaps(THIS, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps)
     696{
     697  #ifdef DEBUG
     698    WriteLog("GetCaps\n");
     699  #endif
     700
     701  if( (NULL==lpDDDriverCaps) && (NULL==lpDDHELCaps) )
     702    return(DDERR_INVALIDPARAMS);
     703
     704  if(NULL!=lpDDDriverCaps)
     705  {
     706    // Caller want Driver Caps
     707
     708    if(sizeof(DDCAPS)!=lpDDDriverCaps->dwSize)
     709      return(DDERR_INVALIDPARAMS);
     710
     711    // Clear structure so we only have to set the supported flags
     712    memset(lpDDDriverCaps,0,sizeof(DDCAPS));
     713
     714    // Reset the size
     715    lpDDDriverCaps->dwSize = sizeof(DDCAPS);
     716
     717    // Now report the CAPs back which we support
     718   lpDDDriverCaps->dwCaps = DDCAPS_BLT |              // We do blitting
     719                            DDCAPS_BLTCOLORFILL |     // We do colorfills
     720                            DDCAPS_COLORKEY |         // We support Colorkeying
     721                            DDCAPS_COLORKEYHWASSIST | // But we (may) use the CPU
     722                            DDCAPS_GDI |              // Maybe check if we are on Voodoo ?
     723                            DDCAPS_PALETTEVSYNC;      // Got VSync
     724
     725    lpDDDriverCaps->dwCaps2 = DDCAPS2_CERTIFIED |         // Who cares so say yes
     726                              DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
     727                              DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
     728                              DDCAPS2_NONLOCALVIDMEM |    // All surfaces are in memory
     729                              DDCAPS2_WIDESURFACES;       // Any size you want!
     730
     731    lpDDDriverCaps->dwCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
     732
     733//    lpDDDriverCaps->dwFXCaps = DDFXCAPS_BLTMIRRORUPDOWN; // DIVE supports this, do we also ?
     734                                                         // Maybe later add stretching support?
     735
     736    lpDDDriverCaps->dwPalCaps = DDPCAPS_8BIT |          // Only 8 Bits pals
     737                                DDPCAPS_ALLOW256 |      // But all 256 colors
     738                                DDPCAPS_VSYNC  |        // Vsync yet
     739                                DDPCAPS_PRIMARYSURFACE; //
     740    lpDDDriverCaps->dwVidMemTotal = 2048*1024;           // total video memory
     741    lpDDDriverCaps->dwVidMemFree  = 2048*1024;            // total free video memory
     742    lpDDDriverCaps->dwNumFourCCCodes;        // number of supported FOURCC codes
     743    lpDDDriverCaps->dwRops[DD_ROP_SPACE];    // supported raster ops
     744    lpDDDriverCaps->dwSVBCaps = DDCAPS_BLT |              // We do blitting
     745                                DDCAPS_BLTCOLORFILL |     // We do colorfills
     746                                DDCAPS_COLORKEY |         // We support Colorkeying
     747                                DDCAPS_COLORKEYHWASSIST;
     748    lpDDDriverCaps->dwSVBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
     749    lpDDDriverCaps->dwSVBFXCaps;             //  .
     750    lpDDDriverCaps->dwSVBRops[DD_ROP_SPACE]; //  .
     751    lpDDDriverCaps->dwVSBCaps = DDCAPS_BLT |              // We do blitting
     752                                DDCAPS_BLTCOLORFILL |     // We do colorfills
     753                                DDCAPS_COLORKEY |         // We support Colorkeying
     754                                DDCAPS_COLORKEYHWASSIST;
     755    lpDDDriverCaps->dwVSBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
     756    lpDDDriverCaps->dwVSBFXCaps;             //  .
     757    lpDDDriverCaps->dwVSBRops[DD_ROP_SPACE]; //  .
     758    lpDDDriverCaps->dwSSBCaps = DDCAPS_BLT |              // We do blitting
     759                                DDCAPS_BLTCOLORFILL |     // We do colorfills
     760                                DDCAPS_COLORKEY |         // We support Colorkeying
     761                                DDCAPS_COLORKEYHWASSIST;
     762    lpDDDriverCaps->dwSSBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
     763    lpDDDriverCaps->dwSSBFXCaps;            //  .
     764    lpDDDriverCaps->dwSSBRops[DD_ROP_SPACE]; //  .
     765    lpDDDriverCaps->dwSVBCaps2 = DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
     766                                 DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
     767                                 DDCAPS2_WIDESURFACES;       // Any size you want!
     768    lpDDDriverCaps->dwNLVBCaps = DDCAPS_BLT |              // We do blitting
     769                                 DDCAPS_BLTCOLORFILL |     // We do colorfills
     770                                 DDCAPS_COLORKEY |         // We support Colorkeying
     771                                 DDCAPS_COLORKEYHWASSIST;
     772    lpDDDriverCaps->dwNLVBCaps2 = DDCAPS2_CANRENDERWINDOWED | // Better check for Voodoo ?!
     773                                  DDCAPS2_COPYFOURCC |        // yepp memcpy will do this
     774                                  DDCAPS2_WIDESURFACES;       // Any size you want!
     775    lpDDDriverCaps->dwNLVBCKeyCaps = DDCKEYCAPS_SRCBLT;      // Only source transparent blitting
     776    lpDDDriverCaps->dwNLVBFXCaps;            //  .
     777    lpDDDriverCaps->dwNLVBRops[DD_ROP_SPACE];//  .
     778    DDSCAPS2 ddsCaps;                 // general surface caps
     779
     780  }
     781
     782  if(NULL!=lpDDHELCaps)
     783  {
     784    // Caler wants HEL Caps
     785    if(sizeof(DDCAPS)!=lpDDHELCaps->dwSize)
     786      return(DDERR_INVALIDPARAMS);
     787
     788  }
     789
     790  return(DD_OK);
     791}
     792//******************************************************************************
     793//******************************************************************************
     794HRESULT __stdcall DrawGetDisplayMode(THIS This, LPDDSURFACEDESC lpDDSurfaceDesc)
     795{
     796  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     797  #ifdef DEBUG
     798    WriteLog("GetDisplayMode\n");
     799  #endif
     800
     801  // Check Parameter
     802  if(NULL==lpDDSurfaceDesc)
     803    return(DDERR_INVALIDPARAMS);
     804
     805  if(sizeof(DDSURFACEDESC)!=lpDDSurfaceDesc->dwSize)
     806    return(DDERR_INVALIDPARAMS);
     807
     808  // We report back the DIVE caps. maybe we should set up a local DDSURFACEDESC
     809  // for the object so we can change the values when we switch modes (or say so)
     810  // as a program may use this function to check the values after a mode change
     811  // An other reason to to so is Voodoo supports maybe more functions
     812
     813  // Tell what we report
     814  lpDDSurfaceDesc->dwFlags  = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
     815  lpDDSurfaceDesc->dwHeight = me->dCaps.ulHorizontalResolution;
     816  lpDDSurfaceDesc->dwWidth  = me->dCaps.ulVerticalResolution;
     817  // Set the PixelFormat
     818  lpDDSurfaceDesc->ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
     819
     820  lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC = me->dCaps.fccColorEncoding;
     821  lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = me->dCaps.ulDepth;
     822  lpDDSurfaceDesc->ddpfPixelFormat.dwRGBAlphaBitMask = 0; // No Alpha support
     823  switch(me->dCaps.ulDepth)
     824  {
     825    case 4:
     826      // Assume that no one will run OS/2 PM with less then 16 colors and try
     827      // to start a DirectX program ;)
     828      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags =  DDPF_RGB | DDPF_PALETTEINDEXED4;
     829      lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0;
     830      lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0;
     831      lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0;
     832      break;
     833    case 8:
     834      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8 |
     835                                                 DDPF_FOURCC;
     836      lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0;
     837      lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0;
     838      lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0;
     839      break;
     840    case 15:
     841    case 16:
     842      lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount = 16; // No sure about 15Bit modes
     843      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
     844      if (FOURCC_R555 == me->dCaps.fccColorEncoding)
     845      {
     846        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00007C00;
     847        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000003E0;
     848        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F;
     849      }
     850      else
     851      {
     852        if(FOURCC_R565 == me->dCaps.fccColorEncoding)
     853        {
     854          lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800;
     855          lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000007E0;
     856          lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000001F;
     857        }
     858        else
     859        {
     860          // R664
     861          lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x0000F800;
     862          lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x000003F0;
     863          lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x0000000F;
     864        }
     865      }
     866      break;
     867    case 24:
     868      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
     869      if(FOURCC_RGB3 == me->dCaps.fccColorEncoding)
     870      {
     871        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     872        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     873        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF;
     874      }
     875      else
     876      {
     877        // BGR3
     878        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x000000FF;
     879        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     880        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
     881      }
     882      break;
     883    case 32:
     884      lpDDSurfaceDesc->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
     885      if(FOURCC_RGB4 == me->dCaps.fccColorEncoding)
     886      {
     887        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     888        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     889        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x000000FF;
     890      }
     891      else
     892      {
     893        // BGR4
     894        lpDDSurfaceDesc->ddpfPixelFormat.dwRBitMask = 0x000000FF;
     895        lpDDSurfaceDesc->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     896        lpDDSurfaceDesc->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
     897      }
     898      break;
     899    default:
     900      #ifdef DEBUG
     901        WriteLog("Unsupported mode\n");
     902      #endif
     903      return(DDERR_UNSUPPORTEDMODE);
     904  }
     905
     906  return(DD_OK);
     907}
     908//******************************************************************************
     909//******************************************************************************
     910HRESULT __stdcall DrawGetDisplayMode4(THIS This, LPDDSURFACEDESC2 lpDDSurfaceDesc2)
     911{
     912  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     913  #ifdef DEBUG
     914    WriteLog("GetDisplayMode\n");
     915  #endif
     916
     917  // Check Parameter
     918  if(NULL==lpDDSurfaceDesc2)
     919    return(DDERR_INVALIDPARAMS);
     920
     921  if(sizeof(DDSURFACEDESC)!=lpDDSurfaceDesc2->dwSize)
     922    return(DDERR_INVALIDPARAMS);
     923
     924  // We report back the DIVE caps. maybe we should set up a local DDSURFACEDESC
     925  // for the object so we can change the values when we switch modes (or say so)
     926  // as a program may use this function to check the values after a mode change
     927  // An other reason to to so is Voodoo supports maybe more functions
     928
     929  // Tell what we report
     930  lpDDSurfaceDesc2->dwFlags  = DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
     931  lpDDSurfaceDesc2->dwHeight = me->dCaps.ulHorizontalResolution;
     932  lpDDSurfaceDesc2->dwWidth  = me->dCaps.ulVerticalResolution;
     933  // Set the PixelFormat
     934  lpDDSurfaceDesc2->ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
     935
     936  lpDDSurfaceDesc2->ddpfPixelFormat.dwFourCC = me->dCaps.fccColorEncoding;
     937  lpDDSurfaceDesc2->ddpfPixelFormat.dwRGBBitCount = me->dCaps.ulDepth;
     938  lpDDSurfaceDesc2->ddpfPixelFormat.dwRGBAlphaBitMask = 0; // No Alpha support
     939  switch(me->dCaps.ulDepth)
     940  {
     941    case 4:
     942      // Assume that no one will run OS/2 PM with less then 16 colors and try
     943      // to start a DirectX program ;)
     944      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags =  DDPF_RGB | DDPF_PALETTEINDEXED4;
     945      lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0;
     946      lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0;
     947      lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0;
     948      break;
     949    case 8:
     950      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_PALETTEINDEXED8 |
     951                                                 DDPF_FOURCC;
     952      lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0;
     953      lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0;
     954      lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0;
     955      break;
     956    case 15:
     957    case 16:
     958      lpDDSurfaceDesc2->ddpfPixelFormat.dwRGBBitCount = 16; // No sure about 15Bit modes
     959      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
     960      if (FOURCC_R555 == me->dCaps.ulDepth)
     961      {
     962        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x00007C00;
     963        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x000003E0;
     964        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x0000001F;
     965      }
     966      else
     967      {
     968        if(FOURCC_R565 == me->dCaps.fccColorEncoding)
     969        {
     970          lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x0000F800;
     971          lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x000007E0;
     972          lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x0000001F;
     973        }
     974        else
     975        {
     976          // R664
     977          lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x0000F800;
     978          lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x000003F0;
     979          lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x0000000F;
     980        }
     981      }
     982      break;
     983    case 24:
     984      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
     985      if(FOURCC_RGB3 == me->dCaps.fccColorEncoding)
     986      {
     987        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     988        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     989        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x000000FF;
     990      }
     991      else
     992      {
     993        // BGR3
     994        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x000000FF;
     995        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     996        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
     997      }
     998      break;
     999    case 32:
     1000      lpDDSurfaceDesc2->ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_FOURCC;
     1001      if(FOURCC_RGB4 == me->dCaps.fccColorEncoding)
     1002      {
     1003        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x00FF0000;
     1004        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     1005        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x000000FF;
     1006      }
     1007      else
     1008      {
     1009        // BGR4
     1010        lpDDSurfaceDesc2->ddpfPixelFormat.dwRBitMask = 0x000000FF;
     1011        lpDDSurfaceDesc2->ddpfPixelFormat.dwGBitMask = 0x0000FF00;
     1012        lpDDSurfaceDesc2->ddpfPixelFormat.dwBBitMask = 0x00FF0000;
     1013      }
     1014      break;
     1015    default:
     1016      #ifdef DEBUG
     1017        WriteLog("Unsupported mode\n");
     1018      #endif
     1019      return(DDERR_UNSUPPORTEDMODE);
     1020  }
     1021
     1022  return(DD_OK);
     1023}
     1024//******************************************************************************
     1025//******************************************************************************
     1026HRESULT __stdcall DrawGetFourCCCodes(THIS, LPDWORD lpNumCodes, LPDWORD lpCodes)
     1027{
     1028  DWORD dwFCC[3] = {FOURCC_LUT8,FOURCC_R565,FOURCC_RGB3};
     1029  #ifdef DEBUG
     1030    WriteLog("GetFourCCCodes\n");
     1031  #endif
     1032
     1033  if(NULL==lpNumCodes)
     1034    return(DDERR_INVALIDPARAMS);
     1035
     1036  if(NULL==lpCodes)
     1037  {
     1038    *lpNumCodes = 3; // LUT8, R565, RGB3 are the FourCC we support for now
     1039  }
     1040  else
     1041  {
     1042    for(int i=0;(i<3)&&(i<*lpNumCodes);i++)
     1043    {
     1044      *lpCodes = dwFCC[i];
     1045      lpCodes +=4;
     1046    }
     1047    if(*lpNumCodes < 3)
     1048      *lpNumCodes = 3;
     1049  }
     1050  return(DD_OK);
     1051}
     1052//******************************************************************************
     1053//******************************************************************************
     1054HRESULT __stdcall DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE FAR *)
     1055{
     1056  #ifdef DEBUG
     1057    WriteLog("GetGDISurface\n");
     1058  #endif
     1059
     1060  return(DD_OK);
     1061}
     1062//******************************************************************************
     1063//******************************************************************************
     1064HRESULT __stdcall DrawGetGDISurface4(THIS, LPDIRECTDRAWSURFACE4 FAR *)
     1065{
     1066  #ifdef DEBUG
     1067    WriteLog("GetGDISurface\n");
     1068  #endif
     1069
     1070  return(DD_OK);
     1071}
     1072//******************************************************************************
     1073//******************************************************************************
     1074HRESULT __stdcall DrawGetMonitorFrequency(THIS This, LPDWORD lpdwFreq)
     1075{
     1076  ULONG ulTime1, ulTime2;
     1077  DWORD dwFlags = DDWAITVB_BLOCKBEGIN;
     1078  #ifdef DEBUG
     1079    WriteLog("GetMonitorFrequency\n");
     1080  #endif
     1081  if(NULL==lpdwFreq)
     1082    return(DDERR_INVALIDPARAMS);
     1083
     1084  if(DD_OK==DrawWaitForVerticalBlank(This, dwFlags, 0))
     1085  {
     1086    ulTime1 = GetTickCount();
     1087    // Timer has an accuracy of 4 ms so call it al least 4 times
     1088    DrawWaitForVerticalBlank(This, dwFlags, 0);
     1089    DrawWaitForVerticalBlank(This, dwFlags, 0);
     1090    DrawWaitForVerticalBlank(This, dwFlags, 0);
     1091    DrawWaitForVerticalBlank(This, dwFlags, 0);
     1092    ulTime2 = GetTickCount();
     1093    ulTime2 -= ulTime1;
     1094    if(ulTime2) // paranoid check to avoid DIV0
     1095      *lpdwFreq = 4000 / ulTime2;
     1096    else
     1097      *lpdwFreq = 70;
     1098  }
     1099  else
     1100  {
     1101    // Assume 70 Hz maybe better return DDERR_UNSUPPORTED if this function isn't mandatory
     1102    *lpdwFreq = 70;
     1103  }
     1104  return(DD_OK);
     1105}
     1106//******************************************************************************
     1107//******************************************************************************
     1108HRESULT __stdcall DrawGetScanLine(THIS, LPDWORD lpdwLine)
     1109{
     1110  BOOL bVertBlank;
     1111  #ifdef DEBUG
     1112    WriteLog("GetScanLine\n");
     1113  #endif
     1114  // ToDO find a way to get this position, so for now simply return DDERR_UNSUPPORTED
     1115  // as we indicated in DDCAPS we don't support this.
     1116
     1117  return(DDERR_UNSUPPORTED);
     1118
     1119  //the following code could be used if we implement this
     1120  /*
     1121  if(NULL==lpdwLine)
     1122    return(DDERR_INVALIDPARAMS);
     1123  DrawGetVertcalBlackStatus(This,&bVertBlank);
     1124  if(bVertBlank)
     1125    return (DDERR_VERTICALBLANKINPROGRESS);
     1126  *lpdwLine = GetLine(); // GetLine would be the function which gets us the line
     1127  return(DD_OK);
     1128  */
     1129}
     1130//******************************************************************************
     1131//******************************************************************************
     1132HRESULT __stdcall DrawGetVerticalBlankStatus(THIS , LPBOOL lpbIsInVB)
     1133{
     1134  #ifdef DEBUG
     1135    WriteLog("GetVerticalBlankStatus\n");
     1136  #endif
     1137  if(NULL==lpbIsInVB)
     1138    return(DDERR_INVALIDPARAMS);
     1139  if(0==io_init1())  // try to get IOPL for the thread
     1140  {
     1141    *lpbIsInVB = (c_inb1(0x3da)&0x08)!=0;
     1142    io_exit1(); // reset IOPL
     1143    return(DD_OK);
     1144  }
     1145
     1146  return(DDERR_UNSUPPORTED);
     1147}
     1148//******************************************************************************
     1149//******************************************************************************
     1150HRESULT __stdcall DrawInitialize(THIS, GUID FAR *)
     1151{
     1152  #ifdef DEBUG
     1153    WriteLog("Initialize\n");
     1154  #endif
     1155
     1156  return(DD_OK);
     1157}
     1158//******************************************************************************
     1159//******************************************************************************
     1160HRESULT __stdcall DrawRestoreDisplayMode(THIS)
     1161{
     1162  #ifdef DEBUG
     1163    WriteLog("RestoreDisplayMod\n");
     1164  #endif
     1165
     1166  return(DD_OK);
     1167}
     1168//******************************************************************************
     1169//******************************************************************************
     1170HRESULT __stdcall DrawSetCooperativeLevel(THIS This, HWND hwndClient, DWORD dwFlags)
     1171{
     1172 OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     1173
     1174  #ifdef DEBUG
     1175    WriteLog("SetCooperativeLevel: hwnd %X, Flags %X\n", hwndClient, dwFlags);
     1176  #endif
     1177
     1178  me->hwndClient = hwndClient;
     1179  #if 0
     1180  OS2DDSubclassWindow(hwndClient);
     1181  #endif
     1182  return(DD_OK);
     1183}
     1184//******************************************************************************
     1185//Backwards compatibility, what's that??
     1186//******************************************************************************
     1187HRESULT __stdcall DrawSetDisplayMode2(THIS This, DWORD dwWidth, DWORD dwHeight,
     1188              DWORD dwBPP, DWORD dwRefreshRate,
     1189              DWORD dwFlags)
     1190{
     1191 OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
     1192
    2821193#ifdef DEBUG
    283   WriteLog("DuplicateSurface\n");
     1194  WriteLog("SetDisplayMode2 to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP);
    2841195#endif
    285   return(DD_OK);
    286 }
    287 //******************************************************************************
    288 //******************************************************************************
    289 HRESULT __stdcall DrawEnumDisplayModes(THIS, DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK )
    290 {
    291 #ifdef DEBUG
    292   WriteLog("EnumDisplayModes\n");
    293 #endif
    294   return(DD_OK);
    295 }
    296 //******************************************************************************
    297 //******************************************************************************
    298 HRESULT __stdcall DrawEnumSurfaces(THIS, DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK )
    299 {
    300 #ifdef DEBUG
    301   WriteLog("EnumSurfaces\n");
    302 #endif
    303   return(DD_OK);
    304 }
    305 //******************************************************************************
    306 //******************************************************************************
    307 HRESULT __stdcall DrawFlipToGDISurface(THIS)
    308 {
    309 #ifdef DEBUG
    310   WriteLog("FlipToGDISurface\n");
    311 #endif
    312   return(DD_OK);
    313 }
    314 //******************************************************************************
    315 //******************************************************************************
    316 HRESULT __stdcall DrawGetCaps(THIS, LPDDCAPS, LPDDCAPS)
    317 {
    318 #ifdef DEBUG
    319   WriteLog("GetCaps\n");
    320 #endif
    321   return(DD_OK);
    322 }
    323 //******************************************************************************
    324 //******************************************************************************
    325 HRESULT __stdcall DrawGetDisplayMode(THIS, LPDDSURFACEDESC)
    326 {
    327 #ifdef DEBUG
    328   WriteLog("GetDisplayMode\n");
    329 #endif
    330   return(DD_OK);
    331 }
    332 //******************************************************************************
    333 //******************************************************************************
    334 HRESULT __stdcall DrawGetFourCCCodes(THIS, LPDWORD, LPDWORD)
    335 {
    336 #ifdef DEBUG
    337   WriteLog("GetFourCCCodes\n");
    338 #endif
    339   return(DD_OK);
    340 }
    341 //******************************************************************************
    342 //******************************************************************************
    343 HRESULT __stdcall DrawGetGDISurface(THIS, LPDIRECTDRAWSURFACE FAR *)
    344 {
    345 #ifdef DEBUG
    346   WriteLog("GetGDISurface\n");
    347 #endif
    348   return(DD_OK);
    349 }
    350 //******************************************************************************
    351 //******************************************************************************
    352 HRESULT __stdcall DrawGetMonitorFrequency(THIS, LPDWORD)
    353 {
    354 #ifdef DEBUG
    355   WriteLog("GetMonitorFrequency\n");
    356 #endif
    357   return(DD_OK);
    358 }
    359 //******************************************************************************
    360 //******************************************************************************
    361 HRESULT __stdcall DrawGetScanLine(THIS, LPDWORD)
    362 {
    363 #ifdef DEBUG
    364   WriteLog("GetScanLine\n");
    365 #endif
    366   return(DD_OK);
    367 }
    368 //******************************************************************************
    369 //******************************************************************************
    370 HRESULT __stdcall DrawGetVerticalBlankStatus(THIS, LPBOOL)
    371 {
    372 #ifdef DEBUG
    373   WriteLog("GetVerticalBlankStatus\n");
    374 #endif
    375   return(DD_OK);
    376 }
    377 //******************************************************************************
    378 //******************************************************************************
    379 HRESULT __stdcall DrawInitialize(THIS, GUID FAR *)
    380 {
    381 #ifdef DEBUG
    382   WriteLog("Initialize\n");
    383 #endif
    384   return(DD_OK);
    385 }
    386 //******************************************************************************
    387 //******************************************************************************
    388 HRESULT __stdcall DrawRestoreDisplayMode(THIS)
    389 {
    390 #ifdef DEBUG
    391   WriteLog("RestoreDisplayMod\n");
    392 #endif
    393   return(DD_OK);
    394 }
    395 //******************************************************************************
    396 //******************************************************************************
    397 HRESULT __stdcall DrawSetCooperativeLevel(THIS, W32_HWND hwndClient, DWORD dwFlags)
    398 {
    399  OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
    400 
    401   dprintf(("SetCooperativeLevel: hwnd %X, Flags %X\n", hwndClient, dwFlags));
    402   if(dwFlags & DDSCL_FULLSCREEN) {
    403         me->fFullScreen = TRUE;
    404   }
    405   else  me->fFullScreen = FALSE;
    406 
    407   me->hwndClient = hwndClient;
    408   OS2MaximizeWindow((HWND)hwndClient);
    409   return(DD_OK);
    410 }
    411 //******************************************************************************
    412 //Backwards compatibility, what's that??
    413 //******************************************************************************
    414 HRESULT __stdcall DrawSetDisplayMode2(THIS, DWORD dwWidth, DWORD dwHeight,
    415                       DWORD dwBPP, DWORD dwRefreshRate,
    416                       DWORD dwFlags)
    417 {
    418  OS2IDirectDraw *me = (OS2IDirectDraw *)This;
    419 
    420   dprintf(("SetDisplayMode2 to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP));
    4211196  me->screenwidth  = dwWidth;
    4221197  me->screenheight = dwHeight;
    4231198  me->screenbpp    = dwBPP;
    424   return(DD_OK);
    425 }
    426 //******************************************************************************
    427 //******************************************************************************
    428 HRESULT __stdcall DrawSetDisplayMode(THIS, DWORD dwWidth, DWORD dwHeight,
    429                      DWORD dwBPP)
     1199//  _interrupt(3);
     1200  return(DD_OK);
     1201}
     1202//******************************************************************************
     1203//******************************************************************************
     1204HRESULT __stdcall DrawSetDisplayMode(THIS This, DWORD dwWidth, DWORD dwHeight,
     1205             DWORD dwBPP)
    4301206{
    4311207 OS2IDirectDraw        *me = (OS2IDirectDraw *)This;
    4321208
    433 //  _interrupt(3);
    434   dprintf(("SetDisplayMode to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP));
     1209#ifdef DEBUG
     1210  WriteLog("SetDisplayMode to %dx%d with %d bits colors\n", dwWidth, dwHeight, dwBPP);
     1211#endif
    4351212  me->screenwidth  = dwWidth;
    4361213  me->screenheight = dwHeight;
    4371214  me->screenbpp    = dwBPP;
    438   return(DD_OK);
    439 }
    440 //******************************************************************************
    441 //******************************************************************************
    442 HRESULT __stdcall DrawWaitForVerticalBlank(THIS, DWORD, W32_HANDLE)
    443 {
    444   dprintf(("WaitForVerticalBlank\n"));
    445   return(DD_OK);
    446 }
    447 //******************************************************************************
    448 /*** Added in the v2 interface ***/
    449 //******************************************************************************
    450 HRESULT __stdcall DrawGetAvailableVidMem(THIS, LPDDSCAPS, LPDWORD, LPDWORD)
    451 {
    452   dprintf(("GetAvailableVidMem\n"));
    453   return(DD_OK);
    454 }
    455 //******************************************************************************
    456 //******************************************************************************
     1215//  _interrupt(3);
     1216  return(DD_OK);
     1217}
     1218//******************************************************************************
     1219//******************************************************************************
     1220HRESULT __stdcall DrawWaitForVerticalBlank(THIS, DWORD dwFlags, HANDLE hEvent)
     1221{
     1222  HRESULT rc;
     1223  #ifdef DEBUG
     1224    WriteLog("WaitForVerticalBlank\n");
     1225  #endif
     1226
     1227  if(DDWAITVB_BLOCKBEGINEVENT == dwFlags) // This parameter isn't support in DX
     1228    return (DDERR_UNSUPPORTED);
     1229
     1230  if(io_init1())  // try to get IOPL for the thread
     1231    return (DDERR_UNSUPPORTED);  // we failed so return error that we don't support this
     1232
     1233  // AT this point we should have IOPL so lets use it!
     1234
     1235  rc = DDERR_INVALIDPARAMS; // set returnvalue to fail
     1236
     1237  if(DDWAITVB_BLOCKBEGIN == dwFlags)
     1238  {
     1239    while ((c_inb1(0x3da)&0x08)!=0); // Wait for end of vert. retrace if one is running
     1240    while ((c_inb1(0x3da)&0x08)==0); // Wait for new start of retrace
     1241    rc = DD_OK;
     1242  }
     1243
     1244  if(DDWAITVB_BLOCKEND == dwFlags)
     1245  {
     1246    rc = DD_OK;
     1247    if((c_inb1(0x3da)&0x08)!=0)        // Are we in a vert. retrace
     1248    {
     1249      while ((c_inb1(0x3da)&0x08)!=0); // Wait for end of retrace
     1250    }
     1251    else
     1252    {
     1253      while ((c_inb1(0x3da)&0x08)==0); // Wait for new start of retrace
     1254      while ((c_inb1(0x3da)&0x08)!=0); // Wait for end of vert. retrace
     1255    }
     1256
     1257  }
     1258
     1259  io_exit1();
     1260
     1261  return (rc);
     1262
     1263}
     1264//******************************************************************************
     1265//*** Added in the v2 interface ***
     1266//******************************************************************************
     1267HRESULT __stdcall DrawGetAvailableVidMem(THIS, LPDDSCAPS lpDDSCaps,
     1268                                         LPDWORD lpdwTotal, LPDWORD lpdwFree)
     1269{
     1270  #ifdef DEBUG
     1271    WriteLog("GetAvailableVidMem\n");
     1272  #endif
     1273
     1274  // Check parameters
     1275  if(NULL==lpDDSCaps)
     1276    return(DDERR_INVALIDPARAMS);
     1277
     1278  if((NULL==lpdwTotal)&&(NULL==lpdwFree))
     1279    return(DDERR_INVALIDPARAMS);
     1280
     1281  if(NULL!=lpdwTotal)
     1282    *lpdwTotal = 2048 *1024;
     1283
     1284  if(NULL!=lpdwFree)
     1285    *lpdwFree = 2048 *1024;
     1286
     1287  return(DD_OK);
     1288}
     1289//******************************************************************************
     1290//
     1291//******************************************************************************
     1292HRESULT __stdcall DrawGetAvailableVidMem4(THIS, LPDDSCAPS2 lpDDSCaps2,
     1293                                         LPDWORD lpdwTotal, LPDWORD lpdwFree)
     1294{
     1295  #ifdef DEBUG
     1296    WriteLog("GetAvailableVidMem\n");
     1297  #endif
     1298
     1299  // Check parameters
     1300  if(NULL==lpDDSCaps2)
     1301    return(DDERR_INVALIDPARAMS);
     1302
     1303  if((NULL==lpdwTotal)&&(NULL==lpdwFree))
     1304    return(DDERR_INVALIDPARAMS);
     1305
     1306  if(NULL!=lpdwTotal)
     1307    *lpdwTotal = 2048 *1024;
     1308
     1309  if(NULL!=lpdwFree)
     1310    *lpdwFree = 2048 *1024;
     1311
     1312  return(DD_OK);
     1313}
     1314//******************************************************************************
     1315//*** Added in the v4 interface ***
     1316//******************************************************************************
     1317HRESULT __stdcall DrawGetSurfaceFromDC(THIS, HDC hdc, LPDIRECTDRAWSURFACE4 *)
     1318{
     1319  #ifdef DEBUG
     1320    WriteLog("GetSurfaceFromDC Unimplemented Stub\n");
     1321  #endif
     1322
     1323  return(DD_OK);
     1324}
     1325//******************************************************************************
     1326//******************************************************************************
     1327HRESULT __stdcall DrawRestoreAllSurfaces(THIS)
     1328{
     1329  #ifdef DEBUG
     1330    WriteLog("RestoreAllSurfaces\n");
     1331  #endif
     1332
     1333  return(DD_OK);
     1334}
     1335//******************************************************************************
     1336//******************************************************************************
     1337HRESULT __stdcall DrawTestCooperativeLevel(THIS)
     1338{
     1339  #ifdef DEBUG
     1340    WriteLog("TestCooperativeLevel\n");
     1341  #endif
     1342
     1343  return(DD_OK);
     1344}
     1345//******************************************************************************
     1346//******************************************************************************
     1347HRESULT __stdcall DrawGetDeviceIdentifier( THIS, LPDDDEVICEIDENTIFIER lpdddi,
     1348                                           DWORD dwFlags)
     1349{
     1350  #ifdef DEBUG
     1351    WriteLog("GetDeviceIdentifier Flags = %d\n",dwFlags);
     1352  #endif
     1353  if(NULL==lpdddi)
     1354    return DDERR_INVALIDPARAMS;
     1355
     1356  memset( lpdddi,
     1357          0,
     1358          sizeof(DDDEVICEIDENTIFIER));
     1359  // ToDo: Cretae a GUID and put some better data inside
     1360  strcpy( lpdddi->szDriver,
     1361          "OS/2 DIVE Driver");
     1362  strcpy( lpdddi->szDescription,
     1363          "ODIN DD Emulation Driver");
     1364  return(DD_OK);
     1365}
     1366//******************************************************************************
     1367//******************************************************************************
     1368VOID OS2IDirectDraw::SwitchDisplay(HWND hwnd)
     1369{
     1370  DWORD dwVType, dwVSize;
     1371  HKEY hkDirectDraw2;
     1372
     1373  if (bScale)
     1374  {
     1375    if (ERROR_SUCCESS==RegOpenKeyA(HKEY_LOCAL_MACHINE,KEY_DIRECT2DRAW,&hkDirectDraw2))
     1376    {
     1377      dwVSize = 4;
     1378      dwVType = REG_DWORD;
     1379      if (ERROR_SUCCESS!=RegQueryValueExA( hkDirectDraw2, "Fullscreen", NULL, &dwVType,
     1380                                         (LPBYTE)&bScale, &dwVSize))
     1381        bScale = FALSE;
     1382    }
     1383    else
     1384      bScale = FALSE;
     1385  }
     1386}
     1387//******************************************************************************
     1388//******************************************************************************
     1389
Note: See TracChangeset for help on using the changeset viewer.