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.

220 lines
6.9 KiB

  1. #include "windows.h"
  2. #include "stdio.h"
  3. #include <winioctl.h>
  4. #include <ntddjoy.h>
  5. #define JOYREADVERSION "Analog JoyRead 7/596\n"
  6. #define INSTRUCTIONS "\nCommands:\n" \
  7. "\t?,h Display this message\n" \
  8. "\t1 Read joy1\n" \
  9. "\t2 Read joy2\n" \
  10. "\tA Open joy1\n" \
  11. "\ta close joy1\n" \
  12. "\tB Open joy2\n" \
  13. "\tb close joy2\n" \
  14. "\tF fast read joy1\n" \
  15. "\tS stats\n" \
  16. "\tx exit\n"
  17. #define PROMPT "Joy!>"
  18. int __cdecl main(int argc, char **argv) {
  19. HANDLE hJoy1 = NULL;
  20. HANDLE hJoy2 = NULL;
  21. BOOL bDone = FALSE;
  22. BOOL bOK;
  23. DWORD dwBytesRead;
  24. JOY_DD_INPUT_DATA JoyData;
  25. JOY_STATISTICS jStats, *pjStats;
  26. char sz[256], cCode;
  27. int i;
  28. printf (JOYREADVERSION);
  29. printf (INSTRUCTIONS);
  30. while (!bDone) {
  31. printf (PROMPT);
  32. if (gets (sz) == NULL) {
  33. sz[0] = 'x';
  34. sz[1] = '\0';
  35. }
  36. cCode = sz[0]; // if user types a blank before the command, too bad
  37. switch (cCode) {
  38. case 'h':
  39. case '?':
  40. printf (INSTRUCTIONS);
  41. break;
  42. case 'A': // open joystick 1
  43. printf ("Open joy1\n");
  44. if (hJoy1 != NULL) {
  45. printf ("joy1 already open\n");
  46. break;
  47. }
  48. hJoy1 = CreateFile(
  49. "\\\\.\\Joy1",
  50. GENERIC_READ | GENERIC_WRITE,
  51. 0,
  52. NULL,
  53. OPEN_EXISTING,
  54. FILE_ATTRIBUTE_NORMAL,
  55. NULL);
  56. printf ("after CreateFile Joy1 0x%08x\n", hJoy1);
  57. if (hJoy1 == INVALID_HANDLE_VALUE) {
  58. printf ("couldn't open joy1\n");
  59. hJoy1 = NULL;
  60. break;
  61. }
  62. printf ("Got handle to Joy1\n");
  63. break;
  64. case 'B': // open joystick 2
  65. printf ("Open joy2\n");
  66. if (hJoy2 != NULL) {
  67. printf ("joy2 already open\n");
  68. break;
  69. }
  70. hJoy2 = CreateFile(
  71. "\\\\.\\Joy2",
  72. GENERIC_READ | GENERIC_WRITE,
  73. 0,
  74. NULL,
  75. OPEN_EXISTING,
  76. FILE_ATTRIBUTE_NORMAL,
  77. NULL);
  78. printf ("after CreateFile Joy2 0x%08x\n", hJoy1);
  79. if (hJoy2 == INVALID_HANDLE_VALUE) {
  80. printf ("couldn't open joy2\n");
  81. hJoy1 = NULL;
  82. break;
  83. }
  84. printf ("Got handle to Joy2\n");
  85. break;
  86. case 'a': // close joy1
  87. printf ("Close joy1\n");
  88. CloseHandle(hJoy1);
  89. printf ("closed joy1 0x%08x\n", hJoy1);
  90. hJoy1 = NULL;
  91. break;
  92. case 'b': // close joy2
  93. printf ("Close joy2\n");
  94. CloseHandle(hJoy2);
  95. printf ("closed joy2 0x%08x\n", hJoy2);
  96. hJoy2 = NULL;
  97. break;
  98. case '1': // read joy1
  99. printf ("Read joy1\n");
  100. if (hJoy1 == NULL) {
  101. printf ("Joy1 not open\n");
  102. break;
  103. }
  104. bOK = ReadFile (hJoy1, &JoyData, sizeof(JoyData), &dwBytesRead, NULL);
  105. if (!bOK) {
  106. printf ("Read failed\n");
  107. break;
  108. }
  109. printf ("%d bytes read\n", dwBytesRead);
  110. printf ("Unplugged %u\n", JoyData.Unplugged);
  111. printf ("Number of Axes %u\n", JoyData.Axi);
  112. printf ("Buttons 0x%04x\n", JoyData.Buttons);
  113. printf ("x, y, z, t axis times in us, %u %u %u %u\n",
  114. JoyData.XTime,
  115. JoyData.YTime,
  116. JoyData.ZTime,
  117. JoyData.TTime);
  118. break;
  119. case '2': // read joy2
  120. printf ("Read joy2\n");
  121. if (hJoy2 == NULL) {
  122. printf ("Joy2 not open\n");
  123. break;
  124. }
  125. bOK = ReadFile (hJoy2, &JoyData, sizeof(JoyData), &dwBytesRead, NULL);
  126. if (!bOK) {
  127. printf ("Read failed\n");
  128. break;
  129. }
  130. printf ("%d bytes read\n", dwBytesRead);
  131. printf ("Unplugged %u\n", JoyData.Unplugged);
  132. printf ("Number of Axes %u\n", JoyData.Axi);
  133. printf ("Buttons 0x%04x\n", JoyData.Buttons);
  134. printf ("x, y, z, t axis times in us, %u %u %u %u\n",
  135. JoyData.XTime,
  136. JoyData.YTime,
  137. JoyData.ZTime,
  138. JoyData.TTime);
  139. break;
  140. case 'F': // fast read joy1
  141. printf ("Fast read joy1\n");
  142. if (hJoy1 == NULL) {
  143. printf ("Joy1 not open\n");
  144. break;
  145. }
  146. for (i = 0; i < 15; i++) {
  147. bOK = ReadFile (hJoy1, &JoyData, sizeof(JoyData), &dwBytesRead, NULL);
  148. }
  149. printf ("Did 15 reads\n");
  150. if (!bOK) {
  151. printf ("Read failed\n");
  152. break;
  153. }
  154. printf ("%d bytes read\n", dwBytesRead);
  155. printf ("Unplugged %u\n", JoyData.Unplugged);
  156. printf ("Number of Axes %u\n", JoyData.Axi);
  157. printf ("Buttons 0x%04x\n", JoyData.Buttons);
  158. printf ("x, y, z, t axis times in us, %u %u %u %u\n",
  159. JoyData.XTime,
  160. JoyData.YTime,
  161. JoyData.ZTime,
  162. JoyData.TTime);
  163. break;
  164. case 'S': // stats
  165. printf ("Stats joy1\n");
  166. if (hJoy1 == NULL) {
  167. printf ("Joy1 not open\n");
  168. break;
  169. }
  170. pjStats = &jStats;
  171. DeviceIoControl (
  172. hJoy1,
  173. (DWORD) IOCTL_JOY_GET_STATISTICS, // instruction to execute
  174. pjStats, sizeof(JOY_STATISTICS), // buffer and size of buffer
  175. pjStats, sizeof(JOY_STATISTICS), // buffer and size of buffer
  176. &dwBytesRead, 0);
  177. printf ("Version %d\n", pjStats->Version);
  178. printf ("NumberOfAxes %d\n", pjStats->NumberOfAxes);
  179. printf ("Frequency %d\n", pjStats->Frequency);
  180. printf ("dwQPCLatency %d\n", pjStats->dwQPCLatency);
  181. printf ("nQuiesceLoop %d\n", pjStats->nQuiesceLoop);
  182. printf ("PolledTooSoon %d\n", pjStats->PolledTooSoon);
  183. printf ("Polls %d\n", pjStats->Polls);
  184. printf ("Timeouts %d\n", pjStats->Timeouts);
  185. break;
  186. case 'x': // done
  187. bDone = TRUE;
  188. break;
  189. default:
  190. printf ("Huh? >%s<\n", sz);
  191. printf (INSTRUCTIONS);
  192. break;
  193. }
  194. }
  195. // Point proven. Be a nice program and close up shop.
  196. if (hJoy1 != NULL) CloseHandle(hJoy1);
  197. if (hJoy2 != NULL) CloseHandle(hJoy2);
  198. return 1;
  199. }