3 * Copyright 1998 Marcus Meissner
7 * - Tomb Raider 2 Demo:
8 * Doesn't accept input yet. Although I am sure I've done everything right...
9 * - WingCommander Prophecy Demo:
19 #include <sys/signal.h>
26 #include "interfaces.h"
34 static IDirectInputA_VTable ddiavt;
35 static IDirectInputDeviceA_VTable SysKeyboardAvt;
36 static IDirectInputDeviceA_VTable SysMouseAvt;
38 HRESULT WINAPI DirectInputCreate32A(HINSTANCE32 hinst, DWORD dwVersion, LPDIRECTINPUT32A *ppDI, LPUNKNOWN punkOuter) {
39 fprintf(stderr,"DirectInputCreate32A(0x%08lx,%04lx,%p,%p)\n",
40 (DWORD)hinst,dwVersion,ppDI,punkOuter
42 (*ppDI) = (LPDIRECTINPUT32A)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInput32A));
44 (*ppDI)->lpvtbl = &ddiavt;
47 /******************************************************************************
50 static HRESULT WINAPI IDirectInputA_EnumDevices(
51 LPDIRECTINPUT32A this,DWORD dwFlags,LPDIENUMDEVICESCALLBACK32A cb,
52 LPVOID context,DWORD x
54 fprintf(stderr,"IDirectInputA(%p)->EnumDevices(0x%08lx,%p,%p,0x%08lx),stub!\n",this,dwFlags,cb,context,x);
58 static ULONG WINAPI IDirectInputA_AddRef(LPDIRECTINPUT32A this) {
62 static ULONG WINAPI IDirectInputA_Release(LPDIRECTINPUT32A this) {
64 HeapFree(GetProcessHeap(),0,this);
70 static HRESULT WINAPI IDirectInputA_CreateDevice(
71 LPDIRECTINPUT32A this,REFGUID rguid,LPDIRECTINPUTDEVICE32A* pdev,
76 StringFromCLSID(rguid,xbuf);
77 fprintf(stderr,"IDirectInputA(%p)->CreateDevice(%s,%p,%p),stub!\n",this,xbuf,pdev,punk);
78 if (!memcmp(&GUID_SysKeyboard,rguid,sizeof(GUID_SysKeyboard))) {
79 *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectInputDevice32A));
81 (*pdev)->lpvtbl = &SysKeyboardAvt;
82 memcpy(&((*pdev)->guid),rguid,sizeof(*rguid));
85 if (!memcmp(&GUID_SysMouse,rguid,sizeof(GUID_SysMouse))) {
86 *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirectInputDevice32A));
88 (*pdev)->lpvtbl = &SysMouseAvt;
89 memcpy(&((*pdev)->guid),rguid,sizeof(*rguid));
95 static HRESULT WINAPI IDirectInputA_QueryInterface(
96 LPDIRECTINPUT32A this,REFIID riid,LPVOID *ppobj
100 StringFromCLSID(riid,xbuf);
101 fprintf(stderr,"IDirectInputA(%p)->QueryInterface(%s,%p)\n",this,xbuf,ppobj);
102 if (!memcmp(&IID_IUnknown,riid,sizeof(*riid))) {
103 this->lpvtbl->fnAddRef(this);
107 if (!memcmp(&IID_IDirectInputA,riid,sizeof(*riid))) {
108 this->lpvtbl->fnAddRef(this);
115 static IDirectInputA_VTable ddiavt= {
116 IDirectInputA_QueryInterface,
117 IDirectInputA_AddRef,
118 IDirectInputA_Release,
119 IDirectInputA_CreateDevice,
120 IDirectInputA_EnumDevices,
126 /******************************************************************************
127 * IDirectInputDeviceA
129 static HRESULT WINAPI IDirectInputDeviceA_SetDataFormat(
130 LPDIRECTINPUTDEVICE32A this,LPCDIDATAFORMAT df
134 fprintf(stderr,"IDirectInputDeviceA(%p)->SetDataFormat(%p)\n",this,df);
136 fprintf(stderr,"df.dwSize %ld\n",df->dwSize);
137 fprintf(stderr,"df.dwObjsize %ld\n",df->dwObjSize);
138 fprintf(stderr,"df.dwFlags 0x%08lx\n",df->dwFlags);
139 fprintf(stderr,"df.dwDataSize %ld\n",df->dwDataSize);
140 fprintf(stderr,"df.dwNumObjs %ld\n",df->dwNumObjs);
142 for (i=0;i<df->dwNumObjs;i++) {
145 if (df->rgodf[i].pguid)
146 StringFromCLSID(df->rgodf[i].pguid,xbuf);
148 strcpy(xbuf,"<no guid>");
149 fprintf(stderr,"df.rgodf[%d].guid %s\n",i,xbuf);
150 fprintf(stderr,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
151 fprintf(stderr," dwType 0x%02lx,dwInstance %ld\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
152 fprintf(stderr,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
158 static HRESULT WINAPI IDirectInputDeviceA_SetCooperativeLevel(
159 LPDIRECTINPUTDEVICE32A this,HWND32 hwnd,DWORD dwflags
161 fprintf(stderr,"IDirectInputDeviceA(%p)->SetCooperativeLevel(0x%08lx,0x%08lx)\n",this,(DWORD)hwnd,dwflags);
165 static HRESULT WINAPI IDirectInputDeviceA_SetProperty(
166 LPDIRECTINPUTDEVICE32A this,REFGUID rguid,LPCDIPROPHEADER ph
171 StringFromCLSID(rguid,xbuf);
173 strcpy(xbuf,"<no guid>");
174 fprintf(stderr,"IDirectInputDeviceA(%p)->SetProperty(%s,%p)\n",this,xbuf,ph);
178 static HRESULT WINAPI IDirectInputDeviceA_SetEventNotification(
179 LPDIRECTINPUTDEVICE32A this,HANDLE32 hnd
181 fprintf(stderr,"IDirectInputDeviceA(%p)->SetEventNotification(0x%08lx)\n",this,(DWORD)hnd);
185 static HRESULT WINAPI IDirectInputDeviceA_GetDeviceData(
186 LPDIRECTINPUTDEVICE32A this,DWORD x,LPDIDEVICEOBJECTDATA dod,
190 fprintf(stderr,"IDirectInputDeviceA(%p)->GetDeviceData(0x%08lx,%p,%p,0x%08lx)\n",this,x,dod,y,z);
195 static HRESULT WINAPI IDirectInputDeviceA_Acquire(LPDIRECTINPUTDEVICE32A this) {
196 fprintf(stderr,"IDirectInputDeviceA(%p)->Aquire()\n",this);
200 static HRESULT WINAPI IDirectInputDeviceA_Unacquire(LPDIRECTINPUTDEVICE32A this) {
201 fprintf(stderr,"IDirectInputDeviceA(%p)->Unaquire()\n",this);
205 static ULONG WINAPI IDirectInputDeviceA_Release(LPDIRECTINPUTDEVICE32A this) {
209 HeapFree(GetProcessHeap(),0,this);
214 extern BYTE InputKeyStateTable[256];
215 extern BYTE vkey2scode[512];
217 static HRESULT WINAPI IDirectInputDeviceA_GetDeviceState(
218 LPDIRECTINPUTDEVICE32A this,DWORD len,LPVOID ptr
221 fprintf(stderr,"IDirectInputDeviceA(%p)->GetDeviceState(0x%08lx,%p)\n",
225 if (len==256) {/* && this_is_a_keyboard */
229 for (i=0;i<256;i++) {
230 if (InputKeyStateTable[i]&0x80)
231 fprintf(stderr,"VKEY %d pressed (DIK 0x%02x\n",i,vkey2scode[i]);
232 ((LPBYTE)ptr)[i]=vkey2scode[InputKeyStateTable[i]]&0x80;
239 static HRESULT WINAPI IDirectInputDeviceA_QueryInterface(
240 LPDIRECTINPUTDEVICE32A this,REFIID riid,LPVOID *ppobj
244 StringFromCLSID(riid,xbuf);
245 fprintf(stderr,"IDirectInputA(%p)->QueryInterface(%s,%p)\n",this,xbuf,ppobj);
246 if (!memcmp(&IID_IUnknown,riid,sizeof(*riid))) {
247 this->lpvtbl->fnAddRef(this);
251 if (!memcmp(&IID_IDirectInputDeviceA,riid,sizeof(*riid))) {
252 this->lpvtbl->fnAddRef(this);
259 static IDirectInputDeviceA_VTable SysKeyboardAvt={
260 IDirectInputDeviceA_QueryInterface,
262 IDirectInputDeviceA_Release,
266 IDirectInputDeviceA_SetProperty,
267 IDirectInputDeviceA_Acquire,
268 IDirectInputDeviceA_Unacquire,
269 IDirectInputDeviceA_GetDeviceState,
270 IDirectInputDeviceA_GetDeviceData,
271 IDirectInputDeviceA_SetDataFormat,
272 IDirectInputDeviceA_SetEventNotification,
273 IDirectInputDeviceA_SetCooperativeLevel,
280 static IDirectInputDeviceA_VTable SysMouseAvt={
281 IDirectInputDeviceA_QueryInterface,
283 IDirectInputDeviceA_Release,
287 IDirectInputDeviceA_SetProperty,
288 IDirectInputDeviceA_Acquire,
289 IDirectInputDeviceA_Unacquire,
290 IDirectInputDeviceA_GetDeviceState,
291 IDirectInputDeviceA_GetDeviceData,
292 IDirectInputDeviceA_SetDataFormat,
293 IDirectInputDeviceA_SetEventNotification,
294 IDirectInputDeviceA_SetCooperativeLevel,