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

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

Uses DIVEWRAP and fixed bug in surface generation (not setting up all values (Pixelformat))

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