home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vr386 / pcdevice.h < prev    next >
C/C++ Source or Header  |  1996-03-19  |  8KB  |  250 lines

  1. // LOW LEVEL PC DEVICE I/O
  2. // INCLUDES TIMER, POWERGLOVE, LCD GLASSES, JOYSTICK AND KEY MONITOR
  3.  
  4. // ALL ROUTINES BY DAVE STAMPE
  5.  
  6. /*
  7.  This code is part of the VR-386 project, created by Dave Stampe.
  8.  VR-386 is a desendent of REND386, created by Dave Stampe and
  9.  Bernie Roehl.  Almost all the code has been rewritten by Dave
  10.  Stampre for VR-386.
  11.  
  12.  Copyright (c) 1994 by Dave Stampe:
  13.  May be freely used to write software for release into the public domain
  14.  or for educational use; all commercial endeavours MUST contact Dave Stampe
  15.  (dstampe@psych.toronto.edu) for permission to incorporate any part of
  16.  this software or source code into their products!  Usually there is no
  17.  charge for under 50-100 items for low-cost or shareware products, and terms
  18.  are reasonable.  Any royalties are used for development, so equipment is
  19.  often acceptable payment.
  20.  
  21.  ATTRIBUTION:  If you use any part of this source code or the libraries
  22.  in your projects, you must give attribution to VR-386 and Dave Stampe,
  23.  and any other authors in your documentation, source code, and at startup
  24.  of your program.  Let's keep the freeware ball rolling!
  25.  
  26.  DEVELOPMENT: VR-386 is a effort to develop the process started by
  27.  REND386, improving programmer access by rewriting the code and supplying
  28.  a standard API.  If you write improvements, add new functions rather
  29.  than rewriting current functions.  This will make it possible to
  30.  include you improved code in the next API release.  YOU can help advance
  31.  VR-386.  Comments on the API are welcome.
  32.  
  33.  CONTACT: dstampe@psych.toronto.edu
  34. */
  35.  
  36.  
  37.  
  38.  
  39. /************ JOYSTICK LOW_LEVEL I/O *************/
  40.  
  41. extern int joystick_j1;       /* raw joystick results */
  42. extern int joystick_j2;       /* updates after raw_joystick_read() */
  43. extern int joystick_j3;
  44. extern int joystick_j4;
  45. extern int joystick_buttons;
  46.                  // range of 0 to 1200 on read
  47.                  // buttons has 4 bits
  48.                  // mask is 3 for joy1, 12 for joy2
  49.                  // and 15 for both
  50.  
  51. int raw_joystick_read(int mask); /* reads joystick to above variables */
  52.                  /* returns 0 if read successful      */
  53.                  /* else try repeating it later       */
  54.  
  55. /*********** TIMER ROUTINES ************/
  56.  
  57.         // reads current timer chip count values
  58. extern unsigned read_timer();
  59.  
  60.      // returns time in msec
  61. extern long current_time();
  62.  
  63.     // sets up timer to frame-synced interrupt, using
  64.     // speed as a guide to desired rate (see init_timer).
  65.     // once set, the hook will be called each timer in with
  66.     // number of calls to video scan end: at zero, it's
  67.     // the end of frame.  Currently used by LCD (Sega) driver
  68.     // Once set, init_timer has no effect if called.
  69. extern int init_frame_lock(unsigned speed, void (*frame_hook)(int));
  70.  
  71.     // sets up timer to 1190000/speed ints per second
  72.     // sets up call to timer_hook (ignored if NULL)
  73.     // has no effect except to set hook if frame_locked hook set
  74. extern int init_timer(unsigned speed, void (*timer_hook)(int));
  75.  
  76.     // current_time() always in msec now: returns 1000 for compatibility
  77. extern int get_ticks_per_second(void);
  78.  
  79.      // delay in msec: replaces delay() function!
  80. extern void tdelay(long d);
  81.  
  82.     // call before rendering begins
  83. extern void register_render_start();
  84.  
  85.     // call after rendering ends
  86. extern void register_render_end();
  87.  
  88.     // returns time of last render in milliseconds
  89. extern long last_render_time();
  90.  
  91.  
  92.  
  93. /************ KEYBOARD MONITOR ROUTINES *********/
  94.  
  95. extern int init_key_monitor();    // enables key monitor
  96.     // useful to turn it off, cause debuggers hate it!
  97.     // returns 0 if already on, else 1
  98.  
  99. extern int is_key_down(int keycode);    // tests if key(keycode) is down
  100.                 // some useful keycodes:
  101.  
  102. extern int keymon_on;
  103.  
  104. #define UP_CURSOR_KEYCODE    0x48
  105. #define DOWN_CURSOR_KEYCODE    0x50
  106. #define LEFT_CURSOR_KEYCODE    0x4B
  107. #define RIGHT_CURSOR_KEYCODE    0x4D
  108.  
  109. #define LEFT_SHIFT_KEYCODE    0x2A  // use BIOS 16.2 instead as these
  110. #define RIGHT_SHIFT_KEYCODE    0x36  // interact with keypad etc.
  111.  
  112.  
  113. /************ SEGA/LCD SWITCHER DRIVER CONTROL ***********/
  114.  
  115. // turn sega driver etc. on with call to driver:
  116. // init_switch_driver("sega");  <see pointer.h>
  117.  
  118. // these are the interface to RENDERING CONTROL
  119.  
  120. extern int left_page;  /* left image video page  */
  121. extern int right_page; /* right image video page */
  122.  
  123.     /* clear: will = 3 once both L,R pages have been seen */
  124. extern volatile int has_switched;
  125.  
  126. // these are for swdrv.c <switcher driver startup>
  127.  
  128. extern void switch_sega(int tf);    // sega isr
  129. extern void switch_LCD_driver(int tf);  // loaded driver isr
  130. extern void sega_off();   // disable LCD to prolong life
  131.  
  132. // these configure the internal Sega driver
  133.  
  134. extern void select_sega_port(int port); /* sets up default Sega data */
  135.  
  136. extern int sega_left;    // LCD driver config fdata
  137. extern int sega_right;
  138. extern int sega_address;
  139. extern int sega_mask;
  140. extern int sega_doff;
  141. extern int sega_port_image;
  142.  
  143. /************** POWERGLOVE ****************/
  144. // almost all are used by glovedrv.c only
  145.  
  146.  
  147.  
  148. #define G_NOKEY 0xFF    // glove BUTTON codes
  149. #define G_START 0x82
  150. #define G_SEL   0x83
  151. #define G_AKEY  0x0A
  152. #define G_BKEY  0x0B
  153. #define G_UP    0x0D
  154. #define G_DOWN  0x0E
  155. #define G_LEFT  0x0C
  156. #define G_RIGHT 0x0F
  157.  
  158. #define G_RECENTER 0
  159.  
  160. // ************ how glove data is read...
  161.  
  162. typedef struct glove_data {
  163.     signed char x,y,z,rot,fingers,keys,gstat1,gstat2,rxflags;
  164.     unsigned int nmissed;  /* number of samples missed */
  165.     } glove_data;
  166.  
  167.     // see format below...
  168.  
  169. // ************ how to read glove...
  170.  
  171. extern void getglove(glove_data *);    /* get data packet from glove */
  172. extern int  glove_ready(void);        /* returns 0 if not ready     */
  173.                                     /*         1 if data ready    */
  174.    /* sets up glove, enters hires mode    */                                    /*         2 if rxflags also valid */
  175.    /* gdeg switches deglitching on or off */
  176.    /* will call timer_init with 6600 and take hook */
  177. #define DEGLITCH   1
  178. #define NODEGLITCH 0
  179. extern void glove_init(int gdeg);
  180.  
  181.   /* reads glove data, with de-glitching */
  182. extern int glove_read(glove_data *g);
  183.  
  184. /************ gesture recognition */
  185.  
  186. #define G_FLAT      0      /* std. gesture classification */
  187. #define G_THUMB_IN  1
  188. #define G_INDEX_IN  2
  189. #define G_MIDDLE_IN 3
  190. #define G_RING_IN   4
  191. #define G_PINCH     5
  192. #define G_FIST      6
  193. #define G_THUMB_OUT 7
  194. #define G_POINT     8
  195. #define G_BADFINGER 9
  196. #define G_RING_OUT  10
  197. #define G_UNKNOWN   11
  198.  
  199.     /* gesture debounce time in # of glove-reads (1/20 sec) */
  200. extern long gesture_time;
  201.  
  202.     /* mapped gesture type: filled after glove read */
  203. extern unsigned char gesture_type;
  204.     /* use to map std. gestures to subset that's more stable */
  205. extern unsigned char gesture_map[];
  206.                                                             /* so gesture_time is valid */
  207. /***** GLOVE DATA SPECIFICATIONS **************
  208.  
  209. x =   X position, 3mm per number
  210. y =   Y position, 3mm per number
  211. z =   distance,  14mm per number
  212. rot = wrist twist. 0 is up 1 is slightly CW, 5 is down,
  213.       11 is slightly CCW.
  214.       About 30 to 40 degrees per count.
  215.  
  216.  Note: exact scaling of all above change with distance! Closer is higher res.
  217.  
  218.  fingers = packed 2-bit values, 0 is open, 3 is (tight) fist:
  219.     Bit format: TtIiMmRr  for Thumb, Index, Middle, and Ring fingers.
  220.  
  221.  keys: $FF or $80 is no key. Responds with 0 to 9 for keys "0" thru "9"
  222.       $82 = START, $83 = SEL, $0A = "A", $0B = "B", 0 is "Center"
  223.             Up,down,left,right are $0D,$0E,$0C,$0F respectively.
  224.  
  225.  gstat1, gstat2 are dummies
  226.  rxflags is valid ONLY after glove_ready returns 2.
  227.  
  228.  nmissed is number of reads since last glove_read call
  229.  
  230.  **********************************************/
  231.  
  232.  
  233.  // POWERGLOVE data for driver config
  234.  
  235. extern int glove_in_port;
  236. extern int glove_out_port;
  237. extern int port_image;
  238.  
  239. extern int glove_data_mask;
  240. extern int glove_write_mask;
  241.  
  242. extern int glove_none_mask;
  243. extern int glove_latch_mask;
  244. extern int glove_clock_mask;
  245. extern int glove_clock_latch;
  246.  
  247. extern int glove_bit_delay;
  248. extern int glove_byte_delay;
  249.  
  250.