patches for DInput and getting memory size when running FreeBSD
Olivier Houchard
doginou at ciO.rg
Wed May 1 12:01:11 CDT 2002
Hi,
Here are a few patches.
The first one is to be applied on dlls/dinput/keyboard/main.c. It is ugly but that's the only way I found to get games that use SetEventNotification for keyboard to work.
The second one is to be applied on memory/global.c. It is not the best way to get memory size on FreeBSD I guess, but it is still better than 16*1024*1024 :)
Thanks for reviewing.
-------------- next part --------------
--- global.c Wed May 1 18:51:27 2002
+++ oldglobal.c Wed May 1 19:00:15 2002
@@ -41,6 +41,10 @@
#include "winerror.h"
#include "msvcrt/excpt.h"
+#ifdef __FreeBSD__
+#include <sys/sysctl.h>
+#endif
+
WINE_DEFAULT_DEBUG_CHANNEL(global);
/* Global arena block */
@@ -1524,7 +1528,10 @@
#ifdef linux
FILE *f;
#endif
-
+#ifdef __FreeBSD__
+ int *tmp;
+ int size_sys;
+#endif
if (time(NULL)==cache_lastchecked) {
memcpy(lpmem,&cached_memstatus,sizeof(MEMORYSTATUS));
return;
@@ -1579,6 +1586,33 @@
/ (TotalPhysical / 100);
}
} else
+#elif defined(__FreeBSD__)
+ sysctlbyname("hw.physmem", NULL, &size_sys, NULL, 0);
+ tmp = malloc(size_sys * sizeof(int));
+ sysctlbyname("hw.physmem", tmp, &size_sys, NULL, 0);
+ if (tmp && *tmp)
+ {
+ lpmem->dwTotalPhys = *tmp;
+ free(tmp);
+ sysctlbyname("hw.usermem", NULL, &size_sys, NULL, 0);
+ tmp = malloc(size_sys * sizeof(int));
+ sysctlbyname("hw.usermem", tmp, &size_sys, NULL, 0);
+ if (tmp && *tmp)
+ {
+ lpmem->dwAvailPhys = *tmp;
+ lpmem->dwTotalPageFile = *tmp;
+ lpmem->dwAvailPageFile = *tmp;
+ lpmem->dwMemoryLoad = lpmem->dwTotalPhys - lpmem->dwAvailPhys;
+ } else
+ {
+ lpmem->dwAvailPhys = lpmem->dwTotalPhys;
+ lpmem->dwTotalPageFile = lpmem->dwTotalPhys;
+ lpmem->dwAvailPageFile = lpmem->dwTotalPhys;
+ lpmem->dwMemoryLoad = 0;
+ }
+ free(tmp);
+
+ } else
#endif
{
/* FIXME: should do something for other systems */
-------------- next part --------------
--- main.c Wed May 1 18:10:43 2002
+++ oldmain.c Wed May 1 18:15:01 2002
@@ -38,6 +38,8 @@
static ICOM_VTABLE(IDirectInputDevice2A) SysKeyboardAvt;
static ICOM_VTABLE(IDirectInputDevice7A) SysKeyboard7Avt;
+static IDirectInputDevice2A* current_lock = NULL;
+
typedef struct SysKeyboardAImpl SysKeyboardAImpl;
struct SysKeyboardAImpl
{
@@ -48,6 +50,8 @@
IDirectInputAImpl *dinput;
+ HANDLE hEvent;
+ HHOOK hook;
/* SysKeyboardAImpl */
BYTE keystate[256];
int acquired;
@@ -205,6 +209,16 @@
return DI_OK;
}
+static LRESULT CALLBACK dinput_keyboard_hook(int code, WPARAM wparam, LPARAM lparam)
+{
+ SysKeyboardAImpl *This;
+ if (current_lock)
+ This = current_lock;
+ if (This->hEvent)
+ SetEvent(This->hEvent);
+ return 1;
+}
+
static HRESULT WINAPI SysKeyboardAImpl_Acquire(LPDIRECTINPUTDEVICE2A iface)
{
ICOM_THIS(SysKeyboardAImpl,iface);
@@ -215,6 +229,7 @@
This->acquired = 1;
}
+ This->hook = SetWindowsHookExW(WH_KEYBOARD, dinput_keyboard_hook, 0, 0);
return DI_OK;
}
@@ -235,6 +250,17 @@
/******************************************************************************
* GetCapabilities : get the device capablitites
*/
+static HRESULT WINAPI SysKeyboardAImpl_SetEventNotification(LPDIRECTINPUTDEVICE2A iface,
+ HANDLE hnd) {
+ ICOM_THIS(SysKeyboardAImpl,iface);
+
+ TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
+
+ This->hEvent = hnd;
+ current_lock = This;
+ return DI_OK;
+}
+
static HRESULT WINAPI SysKeyboardAImpl_GetCapabilities(
LPDIRECTINPUTDEVICE2A iface,
LPDIDEVCAPS lpDIDevCaps)
@@ -277,7 +303,7 @@
SysKeyboardAImpl_GetDeviceState,
SysKeyboardAImpl_GetDeviceData,
IDirectInputDevice2AImpl_SetDataFormat,
- IDirectInputDevice2AImpl_SetEventNotification,
+ SysKeyboardAImpl_SetEventNotification,
IDirectInputDevice2AImpl_SetCooperativeLevel,
IDirectInputDevice2AImpl_GetObjectInfo,
IDirectInputDevice2AImpl_GetDeviceInfo,
@@ -315,7 +341,7 @@
XCAST(GetDeviceState)SysKeyboardAImpl_GetDeviceState,
XCAST(GetDeviceData)SysKeyboardAImpl_GetDeviceData,
XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
- XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
+ XCAST(SetEventNotification)SysKeyboardAImpl_SetEventNotification,
XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
XCAST(GetObjectInfo)IDirectInputDevice2AImpl_GetObjectInfo,
XCAST(GetDeviceInfo)IDirectInputDevice2AImpl_GetDeviceInfo,
More information about the wine-patches
mailing list