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

Last change on this file since 522 was 522, checked in by sandervl, 26 years ago

divewrap bugfixes + removal of FS save/restore macro calls

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