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.

367 lines
13 KiB

  1. //**************************************************************************
  2. //
  3. // DEVICE.H -- Xena Gaming Project
  4. //
  5. // Version 3.XX
  6. //
  7. // Copyright (c) 1997 Microsoft Corporation. All rights reserved.
  8. //
  9. // @doc
  10. // @header DEVICE.H | Global includes and definitions for device interface
  11. //**************************************************************************
  12. #ifndef __DEVICE_H__
  13. #define __DEVICE_H__
  14. //---------------------------------------------------------------------------
  15. // Definitions
  16. //---------------------------------------------------------------------------
  17. #define MAX_DEVICE_UNITS 4
  18. #define MAX_DETECT_ATTEMPTS 5
  19. #define MAX_POLLING_ATTEMPTS 5
  20. #define MAX_CONNECT_ATTEMPTS 2
  21. #define MAX_DEVICE_NAME 64
  22. #define HOT_PLUG_PACKETS 2
  23. #define MAX_DETECT_INTERVAL 2000
  24. #define QUICK_DETECT_TIME 1000
  25. #define QUICK_DETECT_CLOCKS 8
  26. #define IMODE_DIGITAL_STD 0
  27. #define IMODE_DIGITAL_ENH 4
  28. #define IMODE_ANALOG 8
  29. #define IMODE_NONE -1
  30. #define FLAG_WAIT_FOR_CLOCK 1
  31. #define FLAG_START_CLOCK_LOW 2
  32. #define FLAG_START_CLOCK_HIGH 4
  33. #define INTERRUPT_AFTER_PACKET 1
  34. #define INTERRUPT_DURING_PACKET 2
  35. #define TIMEOUT 300
  36. #define MAX_XA_TIMEOUT 1600
  37. #define POLLING_INTERVAL 10
  38. #define INTXA_BIT_MASK 0x01
  39. #define CLOCK_BIT_MASK 0x10
  40. #define DATA0_BIT_MASK 0x20
  41. #define DATA1_BIT_MASK 0x40
  42. #define DATA2_BIT_MASK 0x80
  43. #define AXIS_ONLY_BIT_MASK 0x0f
  44. #define XA_BIT_MASK 0x01
  45. #define YA_BIT_MASK 0x02
  46. #define XB_BIT_MASK 0x04
  47. #define YB_BIT_MASK 0x08
  48. #define XAXIS_BIT_MASK 0x01
  49. #define YAXIS_BIT_MASK 0x02
  50. #define STATUS_GATE_MASK 0x90
  51. //
  52. // Packet Speed Masks
  53. //
  54. #define GAME_SPEED_66K 0
  55. #define GAME_SPEED_83K 1
  56. #define GAME_SPEED_100K 2
  57. #define GAME_SPEED_125K 3
  58. #define GAME_SPEED_RANGE 4
  59. #define GAME_SPEED_BITS 3
  60. //
  61. // Wheel Speed Masks
  62. //
  63. #define WHEEL_SPEED_48K 0
  64. #define WHEEL_SPEED_66K 1
  65. #define WHEEL_SPEED_98K 2
  66. #define WHEEL_SPEED_RANGE 3
  67. #define WHEEL_SPEED_BITS 3
  68. //
  69. // Internal error codes
  70. //
  71. #define ERROR_SUCCESS 0
  72. #define ERROR_HANDSHAKING -1
  73. #define ERROR_LOWCLOCKSTART -2
  74. #define ERROR_HIGHCLOCKSTART -3
  75. #define ERROR_CLOCKFALLING -4
  76. #define ERROR_CLOCKRISING -5
  77. #define ERROR_ERRORBITS -6
  78. #define ERROR_PARITYBITS -7
  79. #define ERROR_EXTRACLOCKS -8
  80. #define ERROR_PHASEBITS -9
  81. #define ERROR_CHECKSUM -10
  82. #define ERROR_XA_TIMEOUT -11
  83. #define ERROR_CLOCKOVERFLOW -12
  84. //
  85. // Packet status codes
  86. //
  87. #define STATUS_SIBLING_ADDED ((NTSTATUS)0x40050001L)
  88. #define STATUS_SIBLING_REMOVED ((NTSTATUS)0x40050002L)
  89. #define STATUS_DEVICE_CHANGED ((NTSTATUS)0x40050003L)
  90. //
  91. // GAMEENUM_OEM_DATA Constants
  92. //
  93. #define OEM_DEVICE_INFO 0
  94. #define OEM_DEVICE_UNIT 1
  95. #define OEM_DEVICE_SIBLING 2
  96. #define OEM_DEVICE_ID 3
  97. #define OEM_DEVICE_DETECTED 4
  98. #define OEM_DEVICE_OBJECT 5
  99. //
  100. // Device Packet Constants
  101. //
  102. #define JOY_RETURNX 0x00000001
  103. #define JOY_RETURNY 0x00000002
  104. #define JOY_RETURNZ 0x00000004
  105. #define JOY_RETURNR 0x00000008
  106. #define JOY_RETURNU 0x00000010
  107. #define JOY_RETURNV 0x00000020
  108. #define JOY_RETURNPOV 0x00000040
  109. #define JOY_RETURNBUTTONS 0x00000080
  110. #define JOY_RETURNRAWDATA 0x00000100
  111. #define JOY_RETURNPOVCTS 0x00000200
  112. #define JOY_RETURNCENTERED 0x00000400
  113. #define JOY_USEDEADZONE 0x00000800
  114. #define JOY_RETURNALL (JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | \
  115. JOY_RETURNR | JOY_RETURNU | JOY_RETURNV | \
  116. JOY_RETURNPOV | JOY_RETURNBUTTONS)
  117. #define JOY_POVCENTERED (USHORT)-1
  118. #define JOY_POVFORWARD 0
  119. #define JOY_POVRIGHT 9000
  120. #define JOY_POVBACKWARD 18000
  121. #define JOY_POVLEFT 27000
  122. //
  123. // HID Force Feature Identifiers
  124. //
  125. #define HIDP_REPORT_ID_1 0x85
  126. #define MSGAME_INPUT_JOYINFOEX 0x01
  127. #define MSGAME_FEATURE_GETID 0x02
  128. #define MSGAME_FEATURE_GETSTATUS 0x03
  129. #define MSGAME_FEATURE_GETACKNAK 0x04
  130. #define MSGAME_FEATURE_GETNAKACK 0x05
  131. #define MSGAME_FEATURE_GETSYNC 0x06
  132. #define MSGAME_FEATURE_RESET 0x07
  133. #define MSGAME_FEATURE_GETVERSION 0x08
  134. //---------------------------------------------------------------------------
  135. // Types
  136. //---------------------------------------------------------------------------
  137. typedef enum
  138. { // @enum DETECT_ORDER | Device detection order
  139. DETECT_FIRST, // @emem Highest priority devices
  140. DETECT_NORMAL, // @emem Default priority devices
  141. DETECT_LAST // @emem Lowest priority devices
  142. } DETECT_ORDER;
  143. //---------------------------------------------------------------------------
  144. // Structures
  145. //---------------------------------------------------------------------------
  146. typedef struct
  147. { // @struct DEVICE_PACKET | Game device packet
  148. ULONG id; // @field Device unit id
  149. ULONG do_other; // @field Packet flags
  150. ULONG dwX; // @field X position
  151. ULONG dwY; // @field Y position
  152. ULONG dwZ; // @field Z position
  153. ULONG dwR; // @field Rudder position
  154. ULONG dwU; // @field U position
  155. ULONG dwV; // @field Z position
  156. ULONG dwPOV; // @field Point of view state
  157. ULONG dwButtons; // @field Button states
  158. ULONG dwButtonNumber; // @field Current button number pressed
  159. } DEVICE_PACKET, *PDEVICE_PACKET;
  160. typedef struct
  161. { // @struct PACKETINFO | Packet acquistion data
  162. ULONG Size; // @field Size of structure
  163. PCHAR DeviceName; // @field Device name string
  164. MSGAME_TRANSACTION Transaction; // @field Transaction type
  165. ULONG Mode; // @field Digital mode indicator
  166. LONG Speed; // @field Transmission speed indicator
  167. LONG LastError; // @field Last internal error result
  168. GAMEPORT PortInfo; // @field Gameport parameters
  169. ULONG Acquisition; // @field Packet acquisition mode
  170. ULONG NumPackets; // @field Number packets received
  171. ULONG TimeStamp; // @field Last packet time in milliseconds
  172. ULONG ClocksSampled; // @field Number of clocks encountered
  173. ULONG B4Transitions; // @field Number of Button 4 transitions
  174. ULONG StartTimeout; // @field Packet start timeout, calibrated
  175. ULONG HighLowTimeout; // @field Packet high-low timeout, calibrated
  176. ULONG LowHighTimeout; // @field Packet low-high timeout, calibrated
  177. ULONG InterruptDelay; // @field Packet interruptdelay, calibrated
  178. ULONG ClockDutyCycle; // @field Packet clock duty cycle, calibrated
  179. ULONG Attempts; // @field Packet attempt count
  180. ULONG Failures; // @field Packet failure count
  181. ULONG DataSize; // @field Size of packet data buffer
  182. PVOID Data; // @field Packet data buffer pointer
  183. } PACKETINFO, *PPACKETINFO;
  184. typedef struct
  185. { // @struct DEVICE_VALUES | Device registry data
  186. ULONG PacketStartTimeout; // @field Packet start timeout in microseconds
  187. ULONG PacketHighLowTimeout; // Packet high-low timeout in microseconds
  188. ULONG PacketLowHighTimeout; // @field Packet low-high timeout in microseconds
  189. ULONG IdStartTimeout; // @field IDstring start timeout in microseconds
  190. ULONG IdHighLowTimeout; // @field IDstring high-low timeout in microseconds
  191. ULONG IdLowHighTimeout; // @field IDstring low-high timeout in microseconds
  192. ULONG InterruptDelay; // @field Interrupt delay timeout in microseconds
  193. ULONG MaxClockDutyCycle; // @field Clock duty cycle timeout in microseconds
  194. ULONG StatusStartTimeout; // @field Status start timeout in microseconds
  195. ULONG StatusHighLowTimeout; // @field Status high-low timeout in microseconds
  196. ULONG StatusLowHighTimeout; // @field Status low-high timeout in microseconds
  197. ULONG StatusGateTimeout; // @field Status gate timeout in microseconds
  198. } DEVICE_VALUES, *PDEVICE_VALUES;
  199. typedef struct
  200. { // @struct DRIVERSERVICES | Device services table
  201. // @field NTSTATUS (*DriverEntry)(VOID) | ConnectDevice | ConnectDevice service procedure
  202. NTSTATUS (*DriverEntry)(VOID);
  203. // @field NTSTATUS (*ConnectDevice)(PortInfo) | ConnectDevice | ConnectDevice service procedure
  204. NTSTATUS (*ConnectDevice)(PGAMEPORT PortInfo);
  205. // @field NTSTATUS (*StartDevice)(PortInfo) | StartDevice | StartDevice service procedure
  206. NTSTATUS (*StartDevice)(PGAMEPORT PortInfo);
  207. // @field NTSTATUS (*ReadReport)(PortInfo, Report) | ReadReport | ReadReport service procedure
  208. NTSTATUS (*ReadReport)(PGAMEPORT PortInfo, PDEVICE_PACKET Report);
  209. // @field NTSTATUS (*StopDevice)(PGAMEPORT PortInfo) | StopDevice | StopDevice service procedure
  210. NTSTATUS (*StopDevice)(PGAMEPORT PortInfo, BOOLEAN TouchHardware);
  211. // @field NTSTATUS (*GetFeature)(PGAMEPORT PortInfo ...) | GetFeature | GetFeature service procedure
  212. NTSTATUS (*GetFeature)(PGAMEPORT PortInfo, HID_REPORT_ID ReportId, PVOID ReportBuffer, ULONG ReportSize, PULONG Returned);
  213. } DRIVERSERVICES, *PDRIVERSERVICES;
  214. typedef struct
  215. { // @struct DEVICEINFO | Game device object
  216. PDRIVERSERVICES Services; // @field Pointer to service table
  217. PGAMEPORT Siblings; // @field Sibling device list
  218. PHID_DESCRIPTOR DevDescriptor; // @field Pointer to device descriptor
  219. PUCHAR RptDescriptor; // @field Pointer to report descriptor
  220. ULONG RptDescSize; // @field Size of report descriptor
  221. ULONG NumDevices; // @field Number of devices detected
  222. ULONG DeviceCount; // @field Number of devices started
  223. LONG DevicePending; // @field Number devices pending
  224. PCHAR DeviceName; // @field Device name string
  225. DETECT_ORDER DetectOrder; // @field Detection priority
  226. BOOLEAN IsAnalog; // @field Analog device flag
  227. USHORT DeviceId; // @field Hid device identifier
  228. PWCHAR HardwareId; // @field Pnp hardware identifier
  229. } DEVICEINFO, *PDEVICEINFO;
  230. //---------------------------------------------------------------------------
  231. // Macros
  232. //---------------------------------------------------------------------------
  233. #define DECLARE_DEVICE(x) extern DEVICEINFO x##Info
  234. #define INSTANCE_DEVICE(x) &x##Info
  235. #define GET_DEVICE_INFO(p) ((PDEVICEINFO)((p)->OemData[OEM_DEVICE_INFO]))
  236. #define SET_DEVICE_INFO(p,x) ((p)->OemData[OEM_DEVICE_INFO]=(ULONG)x)
  237. #define GET_DEVICE_UNIT(p) ((ULONG)((p)->OemData[OEM_DEVICE_UNIT]))
  238. #define SET_DEVICE_UNIT(p,x) ((p)->OemData[OEM_DEVICE_UNIT]=(ULONG)x)
  239. #define GET_DEVICE_SIBLING(p) ((PGAMEPORT)((p)->OemData[OEM_DEVICE_SIBLING]))
  240. #define SET_DEVICE_SIBLING(p,x) ((p)->OemData[OEM_DEVICE_SIBLING]=(ULONG)x)
  241. #define GET_DEVICE_ID(p) ((USHORT)((p)->OemData[OEM_DEVICE_ID]))
  242. #define SET_DEVICE_ID(p,x) ((p)->OemData[OEM_DEVICE_ID]=(USHORT)x)
  243. #define GET_DEVICE_DETECTED(p) ((PDEVICEINFO)((p)->OemData[OEM_DEVICE_DETECTED]))
  244. #define SET_DEVICE_DETECTED(p,x) ((p)->OemData[OEM_DEVICE_DETECTED]=(ULONG)x)
  245. #define GET_DEVICE_OBJECT(p) ((PDEVICE_OBJECT)((p)->OemData[OEM_DEVICE_OBJECT]))
  246. #define SET_DEVICE_OBJECT(p,x) ((p)->OemData[OEM_DEVICE_OBJECT]=(ULONG)x)
  247. //---------------------------------------------------------------------------
  248. // Public Data
  249. //---------------------------------------------------------------------------
  250. extern ULONG POV_Values[];
  251. extern ULONG PollingInterval;
  252. //---------------------------------------------------------------------------
  253. // Procedures
  254. //---------------------------------------------------------------------------
  255. BOOLEAN
  256. DEVICE_IsOddParity (
  257. IN PVOID Data,
  258. IN ULONG Count
  259. );
  260. BOOLEAN
  261. DEVICE_IsCollision (
  262. IN PPACKETINFO DataPacket
  263. );
  264. NTSTATUS
  265. DEVICE_DriverEntry (VOID);
  266. NTSTATUS
  267. DEVICE_GetDeviceDescriptor (
  268. IN PGAMEPORT PortInfo,
  269. OUT PUCHAR Descriptor,
  270. IN ULONG MaxSize,
  271. OUT PULONG Copied
  272. );
  273. NTSTATUS
  274. DEVICE_GetReportDescriptor (
  275. IN PGAMEPORT PortInfo,
  276. OUT PUCHAR Descriptor,
  277. IN ULONG MaxSize,
  278. OUT PULONG Copied
  279. );
  280. NTSTATUS
  281. DEVICE_StartDevice (
  282. IN PGAMEPORT PortInfo,
  283. IN PWCHAR HardwareId
  284. );
  285. NTSTATUS
  286. DEVICE_ReadReport (
  287. IN PGAMEPORT PortInfo,
  288. OUT PUCHAR Report,
  289. IN ULONG MaxSize,
  290. OUT PULONG Copied
  291. );
  292. NTSTATUS
  293. DEVICE_StopDevice (
  294. IN PGAMEPORT PortInfo,
  295. IN BOOLEAN TouchHardware
  296. );
  297. NTSTATUS
  298. DEVICE_GetFeature (
  299. IN PGAMEPORT PortInfo,
  300. IN HID_REPORT_ID ReportId,
  301. OUT PVOID ReportBuffer,
  302. IN ULONG ReportSize,
  303. OUT PULONG Returned
  304. );
  305. //===========================================================================
  306. // End
  307. //===========================================================================
  308. #endif __DEVICE_H__