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

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

Changed to use ODINCRT macros to preserve FS, but still does crash

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