VICTOR.C 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  12. */
  13. /*
  14. * $Source: f:/miner/source/main/rcs/victor.c $
  15. * $Revision: 2.5 $
  16. * $Author: mike $
  17. * $Date: 1995/03/30 16:35:59 $
  18. *
  19. * Routines to access the VictorMaxx helmet.
  20. *
  21. * $Log: victor.c $
  22. * Revision 2.5 1995/03/30 16:35:59 mike
  23. * text localization.
  24. *
  25. * Revision 2.4 1995/03/09 15:34:33 john
  26. * Fixed bug with timeout being too long.
  27. *
  28. * Revision 2.3 1995/03/08 15:42:00 john
  29. * Took out debug code.
  30. *
  31. * Revision 2.2 1995/03/08 15:32:54 john
  32. * Made VictorMaxx head tracking use Greenleaf code.
  33. *
  34. * Revision 2.1 1995/03/06 15:24:03 john
  35. * New screen techniques.
  36. *
  37. * Revision 2.0 1995/02/27 11:31:23 john
  38. * New version 2.0, which has no anonymous unions, builds with
  39. * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  40. *
  41. * Revision 1.13 1994/12/06 16:30:40 yuan
  42. * Localization
  43. *
  44. * Revision 1.12 1994/11/27 23:15:06 matt
  45. * Made changes for new mprintf calling convention
  46. *
  47. * Revision 1.11 1994/11/19 15:14:56 mike
  48. * remove unused code and data
  49. *
  50. * Revision 1.10 1994/11/13 16:32:58 matt
  51. * Made angle averaging work right when yaw is near 0/360 degrees
  52. * Made angle read code empty buffer and use last values
  53. *
  54. * Revision 1.9 1994/11/12 13:47:37 john
  55. * Reenabled the victor screen mode setting code.
  56. *
  57. * Revision 1.8 1994/11/11 18:33:26 john
  58. * Made victor not set screen mode.
  59. *
  60. * Revision 1.7 1994/08/25 18:43:44 john
  61. * First revision of new control code.
  62. *
  63. * Revision 1.6 1994/07/25 10:24:04 john
  64. * Victor stuff.
  65. *
  66. * Revision 1.5 1994/07/22 17:53:32 john
  67. * Added better victormax support.
  68. *
  69. * Revision 1.4 1994/07/21 21:31:31 john
  70. * First cheapo version of VictorMaxx tracking.
  71. *
  72. * Revision 1.3 1994/07/20 21:30:34 john
  73. * Got screen mode change to work.
  74. *
  75. * Revision 1.2 1994/07/20 21:04:31 john
  76. * Add VictorMax VR helment support.
  77. *
  78. * Revision 1.1 1994/07/20 20:49:01 john
  79. * Initial revision
  80. *
  81. *
  82. */
  83. #pragma off (unreferenced)
  84. static char rcsid[] = "$Id: victor.c 2.5 1995/03/30 16:35:59 mike Exp $";
  85. #pragma on (unreferenced)
  86. #define DOS4G
  87. #include <stdio.h>
  88. #include <stdlib.h>
  89. #include <conio.h>
  90. #include "error.h"
  91. #include "mono.h"
  92. #include "args.h"
  93. //#include "serial.h"
  94. #include "victor.h"
  95. #include "text.h"
  96. //#include "commlib.h" //Not included in public release -KRB
  97. //#include "fast.h" //Not included in public release -KRB
  98. #include "key.h"
  99. //This include is just to allow compiling. It doesn't mean it will work. Values in here are only dummy values
  100. #include "nocomlib.h"
  101. int Victor_headset_installed=0;
  102. int Victor_mode=0;
  103. PORT * VictorPort = NULL;
  104. /********************************************************************
  105. * *
  106. * Functions for changing low level VGA registers *
  107. * (c) VictorMaxx Technologies, March 1994 *
  108. * *
  109. ********************************************************************/
  110. // The structure containes all atributes for a VGA mode
  111. typedef struct { // VGA atributes
  112. unsigned char MOR, // Misccellaneous Output register
  113. FCR, // Feature Control Register
  114. ISR0, // Input Status Register 0
  115. ISR1, // Input Status Register 1
  116. SR[5],
  117. CRCT[25]; // Catode Ray Tybe Controller registers
  118. } VGAatr;
  119. VGAatr VGA13 = { 0x27, 1, 0x10, 0x31, // 320x200x256
  120. 3, 9, 0xf, 0, 0xe,
  121. 0x6b, 0x4f, 0x50, 0x8e,
  122. 0x5c, 0x84, 0x4, 0x11,
  123. 0, 0x40, 0, 0, 0, 0, 0,
  124. 0, 0xdf, 0xa2, 0xc7, 0x28,
  125. 0x40, 0xdc, 0xf0, 0xa3, 0xff};
  126. VGAatr VGAi13 = { 0x63, 0x0, 0x10, 0x5, // 320x200x256
  127. 0x3, 0x1, 0xf, 0x0, 0xe,
  128. 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f, 0x0,
  129. 0x41, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9c, 0x8e, 0x8f,
  130. 0x28, 0x40, 0x96, 0xb9, 0xa3, 0xff};
  131. //*******************************************************************
  132. // This function sets the data defined above into proper VGA registers
  133. // in: VGAatr structure
  134. // out: none
  135. void set_mode_atr(VGAatr *vga)
  136. {
  137. unsigned char i;
  138. outp( 0x3c2, vga->MOR );
  139. outp( 0x3c4, 0 );
  140. outp( 0x3c5, 0 ); /* choose index 0, reset */
  141. for(i=1; i<=4; i++) {
  142. outp( 0x3c4, i ); /* choose index i */
  143. outp( 0x3c5, vga->SR[i] ); /* choose index i */
  144. }
  145. outp( 0x3c4, 0 );
  146. outp( 0x3c5, 3 ); /* choose index 0 set 11b*/
  147. /* CRTC Registers */
  148. outp( 0x3d4, 0x11 ); /* WRITE index 11H */
  149. i = inp( 0x3d5 );
  150. outp( 0x3d5, i & 0x7f ); /* ENABLE ACCESS TO THE REGISTERS */
  151. for(i=0; i<=7; i++) {
  152. if(i!=1 && i!=2) {
  153. outp( 0x3d4, i );
  154. outp( 0x3d5, vga->CRCT[i] );
  155. }
  156. }
  157. outp( 0x3d4, 0x11 );
  158. outp( 0x3d5, 128 ); /* DISABLE ACCESS TO 0-7 */
  159. for(i=9; i<23; i++) {
  160. outp( 0x3d4, i );
  161. outp( 0x3d5, vga->CRCT[i] );
  162. }
  163. }
  164. void victor_init_graphics()
  165. {
  166. if (Victor_mode==0) {
  167. Victor_mode = 1;
  168. set_mode_atr(&VGA13);
  169. } else {
  170. Victor_mode = 0;
  171. set_mode_atr(&VGAi13);
  172. }
  173. }
  174. void victor_init_tracking(int serial_port)
  175. {
  176. if (Victor_headset_installed) return;
  177. printf( "%s %d\n", TXT_INIT_VICTOR, serial_port );
  178. if ( (serial_port < 1) || (serial_port > 4) ) {
  179. Error( "Invalid serial port parameter for -maxxtrak!\n" );
  180. }
  181. VictorPort = PortOpenGreenleafFast(serial_port-1, 19200, 'N', 8, 1 );
  182. if ( !VictorPort ) {
  183. printf( "%s %d\n", TXT_SERIAL_FAILURE, VictorPort->status );
  184. return;
  185. }
  186. // printf( "Port opened\n" );
  187. SetDtr( VictorPort, 1 );
  188. // printf( "Step #1\n" );
  189. SetRts( VictorPort, 1 );
  190. // printf( "Step #2\n" );
  191. UseRtsCts( VictorPort, 0 );
  192. // printf( "Step #3\n" );
  193. Victor_headset_installed = 1;
  194. atexit( victor_close_tracking );
  195. WriteChar( VictorPort, 'A' ); // Absolute coordinate mode
  196. WriteChar( VictorPort, 'C' ); // High accuracy mode
  197. WriteChar( VictorPort, 'F' ); // Binary Mode
  198. WriteChar( VictorPort, 'G' ); // Sampling upon request
  199. ClearRXBuffer( VictorPort );
  200. WriteChar( VictorPort, 'S' ); // Request a packet
  201. // {
  202. // int k=0;
  203. // while ( k!=KEY_ESC ) {
  204. // fix y, p, r;
  205. // victor_read_headset_filtered( &y, &p, &r );
  206. // printf( "%d\t%d\t%d\n", y, p, r );
  207. // k = key_inkey();
  208. // }
  209. // }
  210. }
  211. void victor_close_tracking() {
  212. if ( Victor_headset_installed ) {
  213. Victor_headset_installed = 0;
  214. VictorPort = NULL;
  215. }
  216. }
  217. fix v_yaw = 0, v_pitch = 0, v_roll = 0;
  218. void victor_read_headset_raw( fix *yaw, fix *pitch, fix *roll )
  219. {
  220. int y, p, r, count;
  221. static unsigned char buff[6];
  222. ReadBufferTimed(VictorPort, buff, 6, 10);
  223. count = VictorPort->count;
  224. if ( count < 6 ) {
  225. ClearRXBuffer(VictorPort);
  226. WriteChar( VictorPort, 'S' );
  227. *yaw = v_yaw;
  228. *pitch = v_pitch;
  229. *roll = v_roll;
  230. return;
  231. }
  232. WriteChar( VictorPort, 'S' );
  233. y = (short)(buff[0] << 8) | buff[1];
  234. p = (short)(buff[2] << 8) | buff[3];
  235. r = (short)(buff[4] << 8) | buff[5];
  236. v_yaw = *yaw = y;
  237. v_pitch = *pitch = -1*(p - 16384);
  238. v_roll = *roll = -1*(r - 16384);
  239. }
  240. void victor_read_headset_filtered( fix *yaw, fix *pitch, fix *roll )
  241. {
  242. int i;
  243. fix _yaw, _pitch, _roll;
  244. fix t_yaw, t_pitch, t_roll;
  245. fix last_yaw;
  246. t_yaw=t_pitch=t_roll=0;
  247. for (i=0; i<2; i++ ) {
  248. victor_read_headset_raw( &_yaw, &_pitch, &_roll );
  249. //if (i>0)
  250. // if (last_yaw<i2f(90) && _yaw>i2f(270))
  251. // _yaw -= i2f(360);
  252. // else if (_yaw<i2f(90) && last_yaw>i2f(270))
  253. // _yaw += i2f(360);
  254. t_yaw += _yaw;
  255. t_pitch += _pitch;
  256. t_roll += _roll;
  257. last_yaw = _yaw;
  258. }
  259. *yaw = t_yaw / 2;
  260. *pitch = t_pitch / 2;
  261. *roll = t_roll / 2;
  262. }