home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / JOYSTICK.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  50 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  JOYSTICK.C
  5. **
  6. **  Joystick support functions
  7. **
  8. **  Public domain demo by Bob Stout
  9. */
  10.  
  11. #include <dos.h>
  12. #include "snpdosys.h"
  13.  
  14. struct joystick JoyStick;
  15.  
  16. /*
  17. **  read_joystick()
  18. **
  19. **  returns Success_ or Error_
  20. **
  21. **  fills in global JoyStick structure
  22. */
  23.  
  24. Boolean_T read_joystick(void)
  25. {
  26.         union REGS regs;
  27.  
  28.         regs.h.ah = 0x84;                       /* Read the switches    */
  29.         regs.x.dx = 0;
  30.         int86(0x15, ®s, ®s);
  31.         if (regs.x.cflag)
  32.                 return Error_;
  33.         JoyStick.switch_0 = TOBOOL(regs.h.al & 0x10);
  34.         JoyStick.switch_1 = TOBOOL(regs.h.al & 0x20);
  35.         JoyStick.switch_2 = TOBOOL(regs.h.al & 0x40);
  36.         JoyStick.switch_3 = TOBOOL(regs.h.al & 0x80);
  37.  
  38.         regs.h.ah = 0x84;                       /* Read positions       */
  39.         regs.x.dx = 1;
  40.         int86(0x15, ®s, ®s);
  41.         if (regs.x.cflag)
  42.                 return Error_;
  43.         JoyStick.pos_Ax = regs.x.ax;
  44.         JoyStick.pos_Ay = regs.x.bx;
  45.         JoyStick.pos_Bx = regs.x.cx;
  46.         JoyStick.pos_By = regs.x.dx;
  47.  
  48.         return Success_;
  49. }
  50.