I_CYBER.C 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // I_cyber.c
  2. #include <dos.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "st_start.h" // For ST_Message()
  6. // Prototypes
  7. unsigned char *I_AllocLow (int length);
  8. /*
  9. ====================================================
  10. Doom control structure
  11. The keybaord and joystick will add to the values set by the cyberman,
  12. to a maximum of 0x19000 for forwardmove and sidemove. Angleturn is
  13. not bounded at all.
  14. parm normal fast
  15. ----- ------ ----
  16. forwardmove 0xc800 0x19000
  17. sidemove 0xc000 0x14000
  18. angleturn 0x2800000 0x5000000
  19. The keyboard and joystick have a 1/3 second slow turn of 0x1400000 under
  20. normal speed to help aiming.
  21. ====================================================
  22. */
  23. /* old ticcmd_t
  24. typedef struct
  25. {
  26. char forwardmove; // *2048 for move
  27. char sidemove; // *2048 for move
  28. short angleturn; // <<16 for angle delta
  29. short consistancy; // checks for net game
  30. unsigned char chatchar;
  31. unsigned char buttons;
  32. } ticcmd_t;
  33. */
  34. // ticcmd_t as it appears in h2def.h
  35. typedef struct
  36. {
  37. char forwardmove;
  38. char sidemove;
  39. short angleturn;
  40. short consistancy;
  41. unsigned char chatchar;
  42. unsigned char buttons;
  43. unsigned char lookfly;
  44. unsigned char arti;
  45. }ticcmd_t;
  46. #define BT_ATTACK 1
  47. #define BT_USE 2
  48. #define BT_CHANGE 4 // if true, the next 3 bits hold weapon num
  49. #define BT_WEAPONMASK (8+16+32)
  50. #define BT_WEAPONSHIFT 3
  51. //==================================================
  52. //
  53. // CyberMan detection and usage info
  54. //
  55. //==================================================
  56. #define DPMI_INT 0x31
  57. #define MOUSE_INT 0x33
  58. #define DOSMEMSIZE 64 // enough for any SWIFT structure
  59. typedef struct {
  60. short x;
  61. short y;
  62. short z;
  63. short pitch;
  64. short roll;
  65. short yaw;
  66. short buttons;
  67. } SWIFT_3DStatus;
  68. // DPMI real mode interrupt structure
  69. static struct rminfo {
  70. long EDI;
  71. long ESI;
  72. long EBP;
  73. long reserved_by_system;
  74. long EBX;
  75. long EDX;
  76. long ECX;
  77. long EAX;
  78. short flags;
  79. short ES,DS,FS,GS,IP,CS,SP,SS;
  80. } RMI;
  81. typedef struct {
  82. unsigned char deviceType;
  83. unsigned char majorVersion;
  84. unsigned char minorVersion;
  85. unsigned char absRelFlags;
  86. unsigned char centeringFlags;
  87. unsigned char reserved[5];
  88. } StaticDeviceData;
  89. // values for deviceType:
  90. #define DEVTYPE_CYBERMAN 1
  91. short selector;
  92. unsigned short segment; // segment of DOS memory block
  93. SWIFT_3DStatus *cyberstat;
  94. int isCyberPresent; // is CyberMan present?
  95. static union REGS regs;
  96. static struct SREGS sregs;
  97. extern int mousepresent;
  98. //===========================================================
  99. //
  100. // I_StartupCyberMan
  101. //
  102. // If a cyberman is present, init it and set isCyberPresent to 1
  103. //===========================================================
  104. void I_StartupCyberMan(void)
  105. {
  106. StaticDeviceData *pbuf;
  107. ST_Message(" CyberMan: ");
  108. isCyberPresent = 0;
  109. cyberstat = (SWIFT_3DStatus *)I_AllocLow (DOSMEMSIZE);
  110. segment = (int)cyberstat>>4;
  111. pbuf = (StaticDeviceData *)cyberstat;
  112. memset(pbuf, 0, sizeof (StaticDeviceData));
  113. // Use DPMI call 300h to issue mouse interrupt
  114. memset(&RMI, 0, sizeof(RMI));
  115. RMI.EAX = 0x53C1; // SWIFT: Get Static Device Data
  116. RMI.ES = segment;
  117. RMI.EDX = 0;
  118. memset(&sregs, 0, sizeof (sregs));
  119. regs.w.ax = 0x0300; // DPMI: simulate interrupt
  120. regs.w.bx = MOUSE_INT;
  121. regs.w.cx = 0;
  122. regs.x.edi = FP_OFF(&RMI);
  123. sregs.es = FP_SEG(&RMI);
  124. int386x( DPMI_INT, &regs, &regs, &sregs );
  125. if ((short)RMI.EAX != 1)
  126. {
  127. // SWIFT functions not present
  128. ST_Message("Wrong mouse driver - no SWIFT support (AX=%04x).\n",
  129. (unsigned)(short)RMI.EAX);
  130. }
  131. else if (pbuf->deviceType != DEVTYPE_CYBERMAN)
  132. {
  133. // no SWIFT device, or not CyberMan
  134. if (pbuf->deviceType == 0)
  135. {
  136. ST_Message("no SWIFT device connected.\n");
  137. }
  138. else
  139. {
  140. ST_Message("SWIFT device is not a CyberMan! (type=%d)\n",
  141. pbuf->deviceType);
  142. }
  143. }
  144. else
  145. {
  146. ST_Message("CyberMan %d.%02d connected.\n",
  147. pbuf->majorVersion, pbuf->minorVersion);
  148. isCyberPresent = 1;
  149. mousepresent = 0;
  150. }
  151. }
  152. /*
  153. ===============
  154. =
  155. = I_ReadCyberCmds
  156. =
  157. ===============
  158. */
  159. int oldpos;
  160. void I_ReadCyberCmd (ticcmd_t *cmd)
  161. {
  162. int delta;
  163. // Use DPMI call 300h to issue mouse interrupt
  164. memset(&RMI, 0, sizeof(RMI));
  165. RMI.EAX = 0x5301; // SWIFT: Get Position and Buttons
  166. RMI.ES = segment;
  167. RMI.EDX = 0;
  168. memset(&sregs, 0, sizeof (sregs));
  169. regs.w.ax = 0x0300; // DPMI: simulate interrupt
  170. regs.w.bx = MOUSE_INT;
  171. regs.w.cx = 0;
  172. regs.x.edi = FP_OFF(&RMI);
  173. sregs.es = FP_SEG(&RMI);
  174. int386x( DPMI_INT, &regs, &regs, &sregs );
  175. if (cyberstat->y < -7900)
  176. cmd->forwardmove = 0xc800/2048;
  177. else if (cyberstat->y > 7900)
  178. cmd->forwardmove = -0xc800/2048;
  179. if (cyberstat->buttons & 4)
  180. cmd->buttons |= BT_ATTACK;
  181. if (cyberstat->buttons & 2)
  182. cmd->buttons |= BT_USE;
  183. delta = cyberstat->x - oldpos;
  184. oldpos = cyberstat->x;
  185. if (cyberstat->buttons & 1)
  186. { // strafe
  187. if (cyberstat->x < -7900)
  188. cmd->sidemove = -0xc800/2048;
  189. else if (cyberstat->x > 7900)
  190. cmd->sidemove = 0xc800/2048;
  191. else
  192. cmd->sidemove = delta*40/2048;
  193. }
  194. else
  195. {
  196. if (cyberstat->x < -7900)
  197. cmd->angleturn = 0x280;
  198. else if (cyberstat->x > 7900)
  199. cmd->angleturn = -0x280;
  200. else
  201. cmd->angleturn = -delta*0xa/16;
  202. }
  203. }
  204. void I_Tactile (int on, int off, int total)
  205. {
  206. if (!isCyberPresent)
  207. return;
  208. on /= 5;
  209. off /= 5;
  210. total /= 40;
  211. if (on > 255)
  212. on = 255;
  213. if (off > 255)
  214. off = 255;
  215. if (total > 255)
  216. total = 255;
  217. memset(&RMI, 0, sizeof(RMI));
  218. RMI.EAX = 0x5330; // SWIFT: Get Position and Buttons
  219. RMI.EBX = on*256+off;
  220. RMI.ECX = total;
  221. memset(&sregs, 0, sizeof (sregs));
  222. regs.w.ax = 0x0300; // DPMI: simulate interrupt
  223. regs.w.bx = MOUSE_INT;
  224. regs.w.cx = 0;
  225. regs.x.edi = FP_OFF(&RMI);
  226. sregs.es = FP_SEG(&RMI);
  227. int386x( DPMI_INT, &regs, &regs, &sregs );
  228. }