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

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

Updated colorconversion and added some more debugoutput

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