source: trunk/src/ddraw/OS2DDRAW.CPP@ 536

Last change on this file since 536 was 536, checked in by hugh, 26 years ago

Fixed Bug geting divecaps (was not init)

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