Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

283 lines
8.5 KiB

  1. /****************************************************************************
  2. MODULE: joyregst.CPP
  3. Tab stops 5 9
  4. Copyright 1995, 1996, Microsoft Corporation, All Rights Reserved.
  5. PURPOSE: Methods for VJOYD Registry entries
  6. FUNCTIONS:
  7. Author(s): Name:
  8. ---------- ----------------
  9. MEA Manolito E. Adan
  10. Revision History:
  11. -----------------
  12. Version Date Author Comments
  13. ------- ------ ----- -------------------------------------------
  14. 0.1 20-Jun-96 MEA original
  15. 21-Mar-99 waltw Removed unreferenced joyGetOEMProductName,
  16. joyGetOEMForceFeedbackDriverDLLName,
  17. GetRing0DriverName
  18. ****************************************************************************/
  19. #include <windows.h>
  20. #include <mmsystem.h>
  21. #include <regstr.h>
  22. #include <stdio.h>
  23. #include <TCHAR.h>
  24. #include "joyregst.hpp"
  25. #include "sw_error.hpp"
  26. #include "Registry.h"
  27. #include "FFDevice.h"
  28. #ifdef _DEBUG
  29. extern char g_cMsg[160];
  30. #endif
  31. //#define ACKNACK_1_16_DEFAULT 0x0000949A
  32. #define ACKNACK_1_16_DEFAULT 0x0000955A
  33. #define ACKNACK_1_20_DEFAULT 0x0000955A
  34. #define ACKNACK_2_00_DEFAULT 0x0000955A
  35. // Default RTC Spring values
  36. #define RTC_DEF_OFFSET 0
  37. #define RTC_DEF_POS_K 10000
  38. #define RTC_DEF_NEG_K 10000
  39. #define RTC_DEF_POS_SAT 10000
  40. #define RTC_DEF_NEG_SAT 10000
  41. #define RTC_DEF_DEADBAND 0
  42. MMRESULT joyGetForceFeedbackCOMMInterface(
  43. IN UINT id,
  44. IN OUT ULONG *pCOMMInterface,
  45. IN OUT ULONG *pCOMMPort)
  46. {
  47. HKEY hOEMForceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  48. DWORD dataSize = sizeof(DWORD);
  49. RegistryKey oemFFKey(hOEMForceFeedbackKey);
  50. oemFFKey.ShouldClose(TRUE); // Close Key on destruction
  51. oemFFKey.QueryValue(REGSTR_VAL_COMM_INTERFACE, (BYTE*)(pCOMMInterface), dataSize);
  52. MMRESULT lr = oemFFKey.QueryValue(REGSTR_VAL_COMM_PORT, (BYTE*)(pCOMMPort), dataSize);
  53. return lr;
  54. }
  55. MMRESULT joySetForceFeedbackCOMMInterface(
  56. IN UINT id,
  57. IN ULONG ulCOMMInterface,
  58. IN ULONG ulCOMMPort)
  59. {
  60. HKEY hOEMForceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  61. RegistryKey oemFFKey(hOEMForceFeedbackKey);
  62. oemFFKey.ShouldClose(TRUE); // Close Key on destruction
  63. oemFFKey.SetValue(REGSTR_VAL_COMM_INTERFACE, (BYTE*)(&ulCOMMInterface), sizeof(DWORD), REG_DWORD);
  64. MMRESULT lr = oemFFKey.SetValue(REGSTR_VAL_COMM_PORT, (BYTE*)(&ulCOMMPort), sizeof(DWORD), REG_DWORD);
  65. return lr;
  66. }
  67. HKEY joyOpenOEMForceFeedbackKey(UINT id)
  68. {
  69. JOYCAPS JoyCaps;
  70. TCHAR szKey[256];
  71. TCHAR szValue[256];
  72. UCHAR szOEMKey[256];
  73. HKEY hKey;
  74. DWORD dwcb;
  75. LONG lr;
  76. // Note: JOYSTICKID1-16 is zero-based, Registry entries for VJOYD is 1-based.
  77. id++;
  78. if (id > joyGetNumDevs() ) return 0;
  79. // open .. MediaResources\CurentJoystickSettings
  80. joyGetDevCaps((id-1), &JoyCaps, sizeof(JoyCaps));
  81. //
  82. #ifdef _NOJOY
  83. strcpy(JoyCaps.szRegKey,"msjstick.drv<0004>");
  84. #endif
  85. //
  86. //
  87. sprintf(szKey,
  88. "%s\\%s\\%s",
  89. REGSTR_PATH_JOYCONFIG,
  90. JoyCaps.szRegKey,
  91. REGSTR_KEY_JOYCURR);
  92. lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPTSTR) &szKey, 0, ((KEY_ALL_ACCESS & ~WRITE_DAC) & ~WRITE_OWNER), &hKey);
  93. if (lr != ERROR_SUCCESS) return 0;
  94. // Get OEM Key name
  95. dwcb = sizeof(szOEMKey);
  96. sprintf(szValue, "Joystick%d%s", id, REGSTR_VAL_JOYOEMNAME);
  97. lr = RegQueryValueEx(hKey, szValue, 0, 0, (LPBYTE) &szOEMKey, (LPDWORD) &dwcb);
  98. RegCloseKey(hKey);
  99. if (lr != ERROR_SUCCESS) return 0;
  100. // open OEM\name\OEMForceFeedback from ...MediaProperties
  101. sprintf(szKey, "%s\\%s\\%s", REGSTR_PATH_JOYOEM, szOEMKey,
  102. REGSTR_OEMFORCEFEEDBACK);
  103. lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, ((KEY_ALL_ACCESS & ~WRITE_DAC) & ~WRITE_OWNER), &hKey);
  104. if (lr != ERROR_SUCCESS)
  105. return 0;
  106. else
  107. return hKey;
  108. }
  109. /******************************************************
  110. **
  111. ** GetRTCSpringData(UINT id, DICONDITION diCondition[2])
  112. **
  113. ** @funct GetRTCSpringData.
  114. **
  115. ******************************************************/
  116. MMRESULT GetRTCSpringData(UINT id, DICONDITION diCondition[2])
  117. {
  118. ::memset(diCondition, 0, sizeof(DICONDITION) * 2);
  119. HKEY forceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  120. if (forceFeedbackKey == 0) {
  121. return JOYERR_NOCANDO;
  122. }
  123. RegistryKey ffRegKey(forceFeedbackKey);
  124. ffRegKey.ShouldClose(TRUE);
  125. DWORD diCondSize = sizeof(DICONDITION);
  126. HRESULT queryResult = ffRegKey.QueryValue(REGSTR_VAL_RTCSPRING_X, (BYTE*)diCondition, diCondSize);
  127. if (queryResult != ERROR_SUCCESS) { // Must at least have RTC-X
  128. diCondition[0].lOffset = RTC_DEF_OFFSET;
  129. diCondition[0].lPositiveCoefficient = RTC_DEF_POS_K;
  130. diCondition[0].lNegativeCoefficient = RTC_DEF_NEG_K;
  131. diCondition[0].dwPositiveSaturation = RTC_DEF_POS_SAT;
  132. diCondition[0].dwNegativeSaturation = RTC_DEF_NEG_SAT;
  133. diCondition[0].lDeadBand = RTC_DEF_DEADBAND;
  134. ffRegKey.SetValue(REGSTR_VAL_RTCSPRING_X, (BYTE*)diCondition, sizeof(DICONDITION), REG_BINARY);
  135. }
  136. diCondSize = sizeof(DICONDITION);
  137. ffRegKey.QueryValue(REGSTR_VAL_RTCSPRING_Y, (BYTE*)(diCondition+1), diCondSize);
  138. // If there is no Y, then there is no Y, live with it (zep doesn't need y)
  139. return ERROR_SUCCESS;
  140. }
  141. /******************************************************
  142. **
  143. ** GetMapping(UINT id)
  144. **
  145. ** @funct GetMapping.
  146. **
  147. ******************************************************/
  148. DWORD GetMapping(UINT id)
  149. {
  150. DWORD retVal = 0;
  151. HKEY forceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  152. if (forceFeedbackKey == 0) {
  153. return retVal;
  154. }
  155. RegistryKey ffRegKey(forceFeedbackKey);
  156. ffRegKey.ShouldClose(TRUE);
  157. DWORD dataSize = DWORD(sizeof(DWORD));
  158. if (ffRegKey.QueryValue(REGSTR_VAL_MAPPING, (BYTE*)&retVal, dataSize) != ERROR_SUCCESS) {
  159. retVal = 0;
  160. if (g_ForceFeedbackDevice.GetFirmwareVersionMajor() > 1) { // Don't add key for old devices
  161. ffRegKey.SetValue(REGSTR_VAL_MAPPING, (BYTE*)&retVal, sizeof(DWORD), REG_DWORD);
  162. }
  163. }
  164. return retVal;
  165. }
  166. /******************************************************
  167. **
  168. ** GetMappingPercents(UINT id, short mapPercents[], UINT numPercents)
  169. **
  170. ** @funct GetMappingPercents.
  171. **
  172. ******************************************************/
  173. MMRESULT GetMappingPercents(UINT id, short mapPercents[], UINT numPercents)
  174. {
  175. DWORD retVal = 0;
  176. HKEY forceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  177. if (forceFeedbackKey == 0) {
  178. return retVal;
  179. }
  180. RegistryKey ffRegKey(forceFeedbackKey);
  181. ffRegKey.ShouldClose(TRUE);
  182. DWORD dataSize = DWORD(sizeof(short) * numPercents);
  183. return ffRegKey.QueryValue(REGSTR_VAL_MAPPERCENTS, (BYTE*)mapPercents, dataSize);
  184. }
  185. /******************************************************
  186. **
  187. ** GetAckNackMethodFromRegistry(UINT id)
  188. **
  189. ** @mfunct GetAckNackMethodFromRegistry.
  190. **
  191. ******************************************************/
  192. DWORD GetAckNackMethodFromRegistry(UINT id)
  193. {
  194. HKEY forceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  195. if (forceFeedbackKey == 0) {
  196. return JOYERR_NOCANDO;
  197. }
  198. RegistryKey ffRegKey(forceFeedbackKey);
  199. ffRegKey.ShouldClose(TRUE);
  200. DWORD ackNackInfo = 0;
  201. TCHAR firmwareString[32] = "";
  202. ::wsprintf(firmwareString, TEXT("%d.%d-AckNack"), g_ForceFeedbackDevice.GetFirmwareVersionMajor(), g_ForceFeedbackDevice.GetFirmwareVersionMinor());
  203. DWORD querySize = sizeof(DWORD);
  204. HRESULT queryResult = ffRegKey.QueryValue(firmwareString, (BYTE*)&ackNackInfo, querySize);
  205. if ((queryResult != ERROR_SUCCESS)) {
  206. if (g_ForceFeedbackDevice.GetFirmwareVersionMajor() == 1) {
  207. if (g_ForceFeedbackDevice.GetFirmwareVersionMinor() < 20) {
  208. ackNackInfo = ACKNACK_1_16_DEFAULT;
  209. } else { // 1.20 and greater
  210. ackNackInfo = ACKNACK_1_20_DEFAULT;
  211. }
  212. } else { // Firmware greater than 1.0
  213. ackNackInfo = ACKNACK_2_00_DEFAULT; // Use the latest I know of
  214. }
  215. ffRegKey.SetValue(firmwareString, (BYTE*)&ackNackInfo, sizeof(DWORD), REG_DWORD);
  216. }
  217. return ackNackInfo;
  218. }
  219. /******************************************************
  220. **
  221. ** GetSpringOffsetFromRegistry(UINT id)
  222. **
  223. ** @mfunct GetSpringOffsetFromRegistry.
  224. **
  225. ******************************************************/
  226. DWORD GetSpringOffsetFromRegistry(UINT id)
  227. {
  228. HKEY forceFeedbackKey = joyOpenOEMForceFeedbackKey(id);
  229. if (forceFeedbackKey == 0) {
  230. return JOYERR_NOCANDO;
  231. }
  232. RegistryKey ffRegKey(forceFeedbackKey);
  233. ffRegKey.ShouldClose(TRUE);
  234. DWORD offset = 2500;
  235. DWORD querySize = sizeof(DWORD);
  236. HRESULT queryResult = ffRegKey.QueryValue(REGSTR_VAL_SPRING_OFFSET, (BYTE*)&offset, querySize);
  237. if ((queryResult != ERROR_SUCCESS)) {
  238. offset = 2500;
  239. ffRegKey.SetValue(REGSTR_VAL_SPRING_OFFSET, (BYTE*)&offset, sizeof(DWORD), REG_DWORD);
  240. }
  241. return offset;
  242. }