17 #define DX_GUID(id,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) static const GUID id = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}
18 DX_GUID( __fb_IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
19 DX_GUID( __fb_GUID_Key, 0x55728220,0xD33C,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00 );
20 DX_GUID( __fb_GUID_SysKeyboard, 0x6F1D2B61,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00 );
22 static int driver_init(
char *title,
int w,
int h,
int depth,
int refresh_rate,
int flags);
63 typedef HRESULT (WINAPI *
DIRECTDRAWCREATE)(GUID FAR *lpGUID,LPDIRECTDRAW FAR *lplpDD,IUnknown FAR *pUnkOuter);
64 typedef HRESULT (WINAPI *
DIRECTINPUTCREATE)(HINSTANCE hinst,
DWORD dwVersion,LPDIRECTINPUT *lplpDI,LPUNKNOWN pUnkOuter);
76 static LPDIRECTDRAWSURFACE
lpDDS;
78 static LPDIRECTDRAWPALETTE
lpDDP;
80 static LPDIRECTINPUTDEVICE
lpDID;
90 result = IDirectDrawSurface_IsLost(
lpDDS);
91 while (result == DDERR_SURFACELOST) {
94 result = IDirectDrawSurface_Restore(
lpDDS);
95 if (result == DDERR_WRONGMODE) {
105 fwinfo.
cbSize =
sizeof(fwinfo);
111 result = IDirectDrawSurface_IsLost(
lpDDS);
124 src.left = src.top = 0;
127 point.x = point.y = 0;
130 dest.left += point.x;
132 dest.right += point.x;
133 dest.bottom += point.y;
137 }
while (result == DDERR_SURFACELOST);
156 static BOOL WINAPI
ddenum_callback(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
169 LPDIRECTDRAW lpDD1 =
NULL;
170 LPDIRECTDRAWCLIPPER lpDDC =
NULL;
176 DDPIXELFORMAT format;
179 int i, depth, is_rgb =
FALSE, height, flags;
189 dd_library = (HMODULE)LoadLibrary(
"ddraw.dll");
192 di_library = (HMODULE)LoadLibrary(
"dinput.dll");
203 (DirectDrawEnumerateEx(
ddenum_callback, &dev_enum_data, DDENUM_ATTACHEDSECONDARYDEVICES) != DD_OK) ||
207 ddGUID = &dev_enum_data.
guid;
210 if ((!DirectDrawCreate) || (DirectDrawCreate(ddGUID, &lpDD1,
NULL) != DD_OK))
212 res = IDirectDraw_QueryInterface(lpDD1, &__fb_IID_IDirectDraw2, (LPVOID)&
lpDD);
213 IDirectDraw_Release(lpDD1);
224 if (
fb_hInitWindow(WS_POPUP | WS_VISIBLE, 0, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)))
226 if (IDirectDraw2_SetCooperativeLevel(lpDD,
fb_win32.
wnd, DDSCL_ALLOWREBOOT | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) != DD_OK)
240 case 15: depth = 16;
break;
241 case 16: depth = 15;
break;
242 case 24: depth = 32;
break;
243 case 32: depth = 24;
break;
258 style = WS_POPUP | WS_VISIBLE;
260 style = (WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME) | WS_VISIBLE;
262 style &= ~WS_MAXIMIZEBOX;
264 AdjustWindowRect(&
rect, style, 0);
269 if (IDirectDraw2_SetCooperativeLevel(lpDD,
fb_win32.
wnd, DDSCL_NORMAL) != DD_OK)
271 if (IDirectDraw2_CreateClipper(lpDD, 0, &lpDDC,
NULL) != DD_OK)
273 if (IDirectDrawClipper_SetHWnd(lpDDC, 0,
fb_win32.
wnd) != DD_OK)
279 desc.dwSize =
sizeof(desc);
280 desc.dwFlags = DDSD_CAPS;
281 desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
282 if (IDirectDraw2_CreateSurface(lpDD, &desc, &
lpDDS,
NULL) != DD_OK)
286 if (IDirectDrawSurface_SetClipper(
lpDDS, lpDDC) != DD_OK)
289 desc.dwSize =
sizeof(desc);
290 desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
293 desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
294 if (IDirectDraw2_CreateSurface(lpDD, &desc, &
lpDDS_back, 0) != DD_OK)
300 format.dwSize =
sizeof(format);
301 if (IDirectDrawSurface_GetPixelFormat(
lpDDS, &format) != DD_OK)
303 if (!(format.dwFlags & DDPF_RGB))
306 if (format.dwRGBBitCount == 8) {
307 if (IDirectDraw2_CreatePalette(lpDD, DDPCAPS_8BIT | DDPCAPS_INITIALIZE | DDPCAPS_ALLOW256,
314 depth = format.dwRGBBitCount;
315 if ((format.dwRGBBitCount == 16) && (format.dwGBitMask == 0x03E0))
317 if ((format.dwRGBBitCount >= 24) && (format.dwRBitMask == 0xFF))
319 else if ((format.dwRGBBitCount >= 16) && (format.dwRBitMask == 0x1F))
329 for (i = 0; i < 256; i++) {
335 if (IDirectInput_CreateDevice(
lpDI, &__fb_GUID_SysKeyboard, &
lpDID,
NULL) != DI_OK)
339 if (IDirectInputDevice_Acquire(
lpDID) != DI_OK)
358 IDirectInputDevice_Unacquire(
lpDID);
359 IDirectInputDevice_Release(
lpDID);
362 IDirectInput_Release(
lpDI);
368 bltfx.dwSize =
sizeof(bltfx);
370 bltfx.dwFillColor = 0;
371 IDirectDrawSurface_Blt(
lpDDS, &rect,
NULL,
NULL, DDBLT_COLORFILL, &bltfx);
375 IDirectDrawSurface_Release(
lpDDS);
384 IDirectDraw2_RestoreDisplayMode(
lpDD);
387 IDirectDraw2_Release(
lpDD);
414 HANDLE running_event = param;
417 unsigned char keystate[256];
422 SetEvent(running_event);
441 desc.dwSize =
sizeof(desc);
444 result = IDirectDrawSurface_Lock(
lpDDS_back,
NULL, &desc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL);
445 }
while (result == DDERR_SURFACELOST);
446 if (result == DD_OK) {
448 IDirectDrawSurface_Unlock(
lpDDS_back, desc.lpSurface);
456 result = IDirectInputDevice_GetDeviceState(
lpDID, 256, keystate);
457 if ((result == DIERR_NOTACQUIRED) || (result == DIERR_INPUTLOST))
458 IDirectInputDevice_Acquire(
lpDID);
461 for (i = 0; i < 128; i++)
474 static int driver_init(
char *title,
int w,
int h,
int depth,
int refresh_rate,
int flags)
485 win_x = (GetSystemMetrics(SM_CXSCREEN) - w) >> 1;
486 win_y = (GetSystemMetrics(SM_CYSCREEN) - h) >> 1;
497 IDirectDraw2_WaitForVerticalBlank(
lpDD, DDWAITVB_BLOCKBEGIN, 0);
505 int depth = desc->ddpfPixelFormat.dwRGBBitCount;
507 if ((depth == 16) && (desc->ddpfPixelFormat.dwGBitMask == 0x03E0))
509 if (depth == modes->
depth) {
511 modes->
data = (
int *)realloc(modes->
data, modes->
size *
sizeof(
int));
512 modes->
data[modes->
size - 1] = (desc->dwWidth << 16) | desc->dwHeight;
528 library = (HMODULE)LoadLibrary(
"ddraw.dll");
531 DirectDrawCreate = (
DIRECTDRAWCREATE)GetProcAddress(library,
"DirectDrawCreate");
532 if ((!DirectDrawCreate) || (DirectDrawCreate(
NULL, &dd1,
NULL) != DD_OK)) {
533 FreeLibrary(library);
536 res = IDirectDraw_QueryInterface(dd1, &__fb_IID_IDirectDraw2, (LPVOID)&dd2);
537 IDirectDraw_Release(dd1);
539 FreeLibrary(library);
545 if (IDirectDraw2_EnumDisplayModes(dd2, DDEDM_STANDARDVGAMODES,
NULL, (LPVOID)&modes,
fetch_modes_callback) != DD_OK)
549 IDirectDraw_Release(dd2);
550 FreeLibrary(library);