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

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

Changhed from Isequence to DPA for managing rectangles and surfaces

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