3 * Copyright 1998 Marcus Meissner
7 * - Tomb Raider 2 Demo:
8 * Playable using keyboard only.
9 * - WingCommander Prophecy Demo:
10 * Doesn't get Input Focus.
12 * FIXME: The keyboard handling needs to (and will) be merged into keyboard.c
13 * (The current implementation is currently only a proof of concept and
23 #include <sys/signal.h>
30 #include "interfaces.h"
37 extern BYTE InputKeyStateTable
[256];
38 extern BYTE vkey2scode
[512];
40 static IDirectInputA_VTable ddiavt
;
41 static IDirectInputDeviceA_VTable SysKeyboardAvt
;
42 static IDirectInputDeviceA_VTable SysMouseAvt
;
44 HRESULT WINAPI
DirectInputCreate32A(HINSTANCE32 hinst
, DWORD dwVersion
, LPDIRECTINPUT32A
*ppDI
, LPUNKNOWN punkOuter
) {
45 fprintf(stderr
,"DirectInputCreate32A(0x%08lx,%04lx,%p,%p)\n",
46 (DWORD
)hinst
,dwVersion
,ppDI
,punkOuter
48 (*ppDI
) = (LPDIRECTINPUT32A
)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInput32A
));
50 (*ppDI
)->lpvtbl
= &ddiavt
;
53 /******************************************************************************
56 static HRESULT WINAPI
IDirectInputA_EnumDevices(
57 LPDIRECTINPUT32A
this,DWORD dwFlags
,LPDIENUMDEVICESCALLBACK32A cb
,
58 LPVOID context
,DWORD x
60 fprintf(stderr
,"IDirectInputA(%p)->EnumDevices(0x%08lx,%p,%p,0x%08lx),stub!\n",this,dwFlags
,cb
,context
,x
);
64 static ULONG WINAPI
IDirectInputA_AddRef(LPDIRECTINPUT32A
this) {
68 static ULONG WINAPI
IDirectInputA_Release(LPDIRECTINPUT32A
this) {
70 HeapFree(GetProcessHeap(),0,this);
76 static HRESULT WINAPI
IDirectInputA_CreateDevice(
77 LPDIRECTINPUT32A
this,REFGUID rguid
,LPDIRECTINPUTDEVICE32A
* pdev
,
82 WINE_StringFromCLSID(rguid
,xbuf
);
83 fprintf(stderr
,"IDirectInputA(%p)->CreateDevice(%s,%p,%p),stub!\n",this,xbuf
,pdev
,punk
);
84 if (!memcmp(&GUID_SysKeyboard
,rguid
,sizeof(GUID_SysKeyboard
))) {
85 *pdev
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysKeyboard32A
));
87 (*pdev
)->lpvtbl
= &SysKeyboardAvt
;
88 memcpy(&((*pdev
)->guid
),rguid
,sizeof(*rguid
));
89 memset(((LPSYSKEYBOARD32A
)(*pdev
))->keystate
,0,256);
92 if (!memcmp(&GUID_SysMouse
,rguid
,sizeof(GUID_SysMouse
))) {
93 *pdev
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirectInputDevice32A
));
95 (*pdev
)->lpvtbl
= &SysMouseAvt
;
96 memcpy(&((*pdev
)->guid
),rguid
,sizeof(*rguid
));
102 static HRESULT WINAPI
IDirectInputA_QueryInterface(
103 LPDIRECTINPUT32A
this,REFIID riid
,LPVOID
*ppobj
107 WINE_StringFromCLSID(riid
,xbuf
);
108 fprintf(stderr
,"IDirectInputA(%p)->QueryInterface(%s,%p)\n",this,xbuf
,ppobj
);
109 if (!memcmp(&IID_IUnknown
,riid
,sizeof(*riid
))) {
110 this->lpvtbl
->fnAddRef(this);
114 if (!memcmp(&IID_IDirectInputA
,riid
,sizeof(*riid
))) {
115 this->lpvtbl
->fnAddRef(this);
122 static HRESULT WINAPI
IDirectInputA_Initialize(
123 LPDIRECTINPUT32A
this,HINSTANCE32 hinst
,DWORD x
125 return DIERR_ALREADYINITIALIZED
;
128 static IDirectInputA_VTable ddiavt
= {
129 IDirectInputA_QueryInterface
,
130 IDirectInputA_AddRef
,
131 IDirectInputA_Release
,
132 IDirectInputA_CreateDevice
,
133 IDirectInputA_EnumDevices
,
136 IDirectInputA_Initialize
139 /******************************************************************************
140 * IDirectInputDeviceA
142 static HRESULT WINAPI
IDirectInputDeviceA_SetDataFormat(
143 LPDIRECTINPUTDEVICE32A
this,LPCDIDATAFORMAT df
147 fprintf(stderr,"IDirectInputDeviceA(%p)->SetDataFormat(%p)\n",this,df);
149 fprintf(stderr,"df.dwSize %ld\n",df->dwSize);
150 fprintf(stderr,"df.dwObjsize %ld\n",df->dwObjSize);
151 fprintf(stderr,"df.dwFlags 0x%08lx\n",df->dwFlags);
152 fprintf(stderr,"df.dwDataSize %ld\n",df->dwDataSize);
153 fprintf(stderr,"df.dwNumObjs %ld\n",df->dwNumObjs);
155 for (i=0;i<df->dwNumObjs;i++) {
158 if (df->rgodf[i].pguid)
159 WINE_StringFromCLSID(df->rgodf[i].pguid,xbuf);
161 strcpy(xbuf,"<no guid>");
162 fprintf(stderr,"df.rgodf[%d].guid %s\n",i,xbuf);
163 fprintf(stderr,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
164 fprintf(stderr," dwType 0x%02lx,dwInstance %ld\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
165 fprintf(stderr,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
171 static HRESULT WINAPI
IDirectInputDeviceA_SetCooperativeLevel(
172 LPDIRECTINPUTDEVICE32A
this,HWND32 hwnd
,DWORD dwflags
174 fprintf(stderr
,"IDirectInputDeviceA(%p)->SetCooperativeLevel(0x%08lx,0x%08lx)\n",this,(DWORD
)hwnd
,dwflags
);
178 static HRESULT WINAPI
IDirectInputDeviceA_SetProperty(
179 LPDIRECTINPUTDEVICE32A
this,REFGUID rguid
,LPCDIPROPHEADER ph
184 WINE_StringFromCLSID(rguid
,xbuf
);
186 sprintf(xbuf
,"<special guid %ld>",(DWORD
)rguid
);
187 fprintf(stderr
,"IDirectInputDeviceA(%p)->SetProperty(%s,%p)\n",this,xbuf
,ph
);
188 if (!HIWORD(rguid
)) {
189 switch ((DWORD
)rguid
) {
190 case DIPROP_BUFFERSIZE
: {
191 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
193 fprintf(stderr
," buffersize = %ld\n",pd
->dwData
);
197 fprintf(stderr
," unknown type %ld\n",(DWORD
)rguid
);
204 static HRESULT WINAPI
IDirectInputDeviceA_SetEventNotification(
205 LPDIRECTINPUTDEVICE32A
this,HANDLE32 hnd
207 fprintf(stderr
,"IDirectInputDeviceA(%p)->SetEventNotification(0x%08lx)\n",this,(DWORD
)hnd
);
211 static HRESULT WINAPI
IDirectInputDeviceA_GetDeviceData(
212 LPDIRECTINPUTDEVICE32A
this,DWORD dodsize
,LPDIDEVICEOBJECTDATA dod
,
213 LPDWORD entries
,DWORD flags
215 /* fprintf(stderr,"IDirectInputDeviceA(%p)->GetDeviceData(%ld,%p,%p(0x%08lx),0x%08lx)\n",this,dodsize,dod,entries,*entries,flags);*/
220 static HRESULT WINAPI
IDirectInputDeviceA_Acquire(LPDIRECTINPUTDEVICE32A
this) {
221 fprintf(stderr
,"IDirectInputDeviceA(%p)->Aquire()\n",this);
225 static HRESULT WINAPI
IDirectInputDeviceA_Unacquire(LPDIRECTINPUTDEVICE32A
this) {
226 fprintf(stderr
,"IDirectInputDeviceA(%p)->Unaquire()\n",this);
230 static ULONG WINAPI
IDirectInputDeviceA_Release(LPDIRECTINPUTDEVICE32A
this) {
234 HeapFree(GetProcessHeap(),0,this);
238 static HRESULT WINAPI
SysKeyboardA_SetProperty(
239 LPDIRECTINPUTDEVICE32A
this,REFGUID rguid
,LPCDIPROPHEADER ph
241 LPSYSKEYBOARD32A kthis
= (LPSYSKEYBOARD32A
)this;
245 WINE_StringFromCLSID(rguid
,xbuf
);
247 sprintf(xbuf
,"<special guid %ld>",(DWORD
)rguid
);
248 fprintf(stderr
,"SysKeyboardA(%p)->SetProperty(%s,%p)\n",this,xbuf
,ph
);
249 fprintf(stderr
," size is %ld, headersize is %ld,obj is %ld,how is %ld\n",ph
->dwSize
,ph
->dwHeaderSize
,ph
->dwObj
,ph
->dwHow
);
250 if (!HIWORD(rguid
)) {
251 switch ((DWORD
)rguid
) {
252 case DIPROP_BUFFERSIZE
: {
253 LPCDIPROPDWORD pd
= (LPCDIPROPDWORD
)ph
;
255 fprintf(stderr
," buffersize = %ld\n",pd
->dwData
);
259 fprintf(stderr
," unknown type %ld\n",(DWORD
)rguid
);
266 static HRESULT WINAPI
SysKeyboardA_GetDeviceState(
267 LPDIRECTINPUTDEVICE32A
this,DWORD len
,LPVOID ptr
274 if (InputKeyStateTable
[i
]&0x80) {
275 ((LPBYTE
)ptr
)[vkey2scode
[i
] ]=0x80;
276 ((LPBYTE
)ptr
)[vkey2scode
[i
]|0x80]=0x80;
280 fprintf(stderr
,"whoops, SysKeyboardA_GetDeviceState got len %ld?\n",len
);
284 static HRESULT WINAPI
SysKeyboardA_GetDeviceData(
285 LPDIRECTINPUTDEVICE32A
this,DWORD dodsize
,LPDIDEVICEOBJECTDATA dod
,
286 LPDWORD entries
,DWORD flags
289 LPSYSKEYBOARD32A kthis
= (LPSYSKEYBOARD32A
)this;
291 /* fprintf(stderr,"SysKeyboardA(%p)->GetDeviceData(%ld,%p,%p(%ld),0x%08lx)\n",this,dodsize,dod,entries,entries?*entries:0,flags);*/
297 for (n
=i
=0;(i
<256) && (n
<*entries
);i
++) {
298 if (kthis
->keystate
[i
] == (InputKeyStateTable
[i
]&0x80))
302 dod
[n
].dwOfs
= vkey2scode
[i
];
303 dod
[n
].dwData
= InputKeyStateTable
[i
]&0x80;
304 dod
[n
].dwTimeStamp
= 0; /* umm */
305 dod
[n
].dwSequence
= 0; /* umm */
308 if (!(flags
& DIGDD_PEEK
))
309 kthis
->keystate
[i
] = InputKeyStateTable
[i
]&0x80;
315 static HRESULT WINAPI
SysKeyboardA_Acquire(LPDIRECTINPUTDEVICE32A
this) {
316 fprintf(stderr
,"SysKeyboardA(%p)->Aquire()\n",this);
320 static HRESULT WINAPI
SysKeyboardA_Unacquire(LPDIRECTINPUTDEVICE32A
this) {
321 fprintf(stderr
,"SysKeyboardA(%p)->Unaquire()\n",this);
326 static HRESULT WINAPI
IDirectInputDeviceA_GetDeviceState(
327 LPDIRECTINPUTDEVICE32A
this,DWORD len
,LPVOID ptr
329 fprintf(stderr
,"IDirectInputDeviceA(%p)->GetDeviceState(0x%08lx,%p)\n",
335 static HRESULT WINAPI
IDirectInputDeviceA_QueryInterface(
336 LPDIRECTINPUTDEVICE32A
this,REFIID riid
,LPVOID
*ppobj
340 WINE_StringFromCLSID(riid
,xbuf
);
341 fprintf(stderr
,"IDirectInputA(%p)->QueryInterface(%s,%p)\n",this,xbuf
,ppobj
);
342 if (!memcmp(&IID_IUnknown
,riid
,sizeof(*riid
))) {
343 this->lpvtbl
->fnAddRef(this);
347 if (!memcmp(&IID_IDirectInputDeviceA
,riid
,sizeof(*riid
))) {
348 this->lpvtbl
->fnAddRef(this);
355 static IDirectInputDeviceA_VTable SysKeyboardAvt
={
356 IDirectInputDeviceA_QueryInterface
,
358 IDirectInputDeviceA_Release
,
362 SysKeyboardA_SetProperty
,
363 SysKeyboardA_Acquire
,
364 SysKeyboardA_Unacquire
,
365 SysKeyboardA_GetDeviceState
,
366 SysKeyboardA_GetDeviceData
,
367 IDirectInputDeviceA_SetDataFormat
,
368 IDirectInputDeviceA_SetEventNotification
,
369 IDirectInputDeviceA_SetCooperativeLevel
,
376 static IDirectInputDeviceA_VTable SysMouseAvt
={
377 IDirectInputDeviceA_QueryInterface
,
379 IDirectInputDeviceA_Release
,
383 IDirectInputDeviceA_SetProperty
,
384 IDirectInputDeviceA_Acquire
,
385 IDirectInputDeviceA_Unacquire
,
386 IDirectInputDeviceA_GetDeviceState
,
387 IDirectInputDeviceA_GetDeviceData
,
388 IDirectInputDeviceA_SetDataFormat
,
389 IDirectInputDeviceA_SetEventNotification
,
390 IDirectInputDeviceA_SetCooperativeLevel
,