home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gchsrc31 / include / joystick.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  1.9 KB  |  76 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is part of the Atari Machine Specific Library,
  4. //  and is Copyright 1992 by Warwick W. Allison.
  5. //
  6. //  You are free to copy and modify these sources, provided you acknoledge
  7. //  the origin by retaining this notice, and adhere to the conditions
  8. //  described in the file COPYING.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef _Joystick_h
  13. #define _Joystick_h
  14. //////////////////////////////////////////////////////////////
  15. //
  16. //  Support for direct Joystick access.
  17. //  Both joysticks are available, and can be accessed
  18. //  in a variety of ways.
  19. //
  20. //////////////////////////////////////////////////////////////
  21. #include <bool.h>
  22.  
  23. enum JoystickDirection {    J_0, J_U, J_D, J_UD, J_L, J_UL, J_DL, J_UDL,
  24.                             J_R, J_UR, J_DR, J_UDR, J_LR, J_ULR, J_DLR, J_UDLR };
  25.  
  26. class Joystick
  27. {
  28. public:
  29.     Joystick(int port=1);
  30.     ~Joystick();
  31.  
  32.     JoystickDirection Way();
  33.  
  34.     bool Passive();
  35.     bool Up();
  36.     bool Down();
  37.     bool Left();
  38.     bool Right();
  39.  
  40.     // NOTE: Trigger 1 only works if joystick 0 is being used,
  41.     //       otherwise it is diverted as RightButton of the mouse.
  42.     //      (Blame Atari)
  43.     //
  44.     bool Trigger();
  45.  
  46.     // -1, 0, or +1 interpretation of joystick
  47.     int x();
  48.     int y();
  49.  
  50. private:
  51.     volatile int (*Flags);
  52. };
  53.  
  54.  
  55. // Below is private
  56.  
  57.  
  58. inline JoystickDirection Joystick::Way() { return *Flags&J_UDLR; }
  59.  
  60. inline bool Joystick::Passive() { return !*Flags; }
  61. inline bool Joystick::Up() { return !!(*Flags&J_U); }
  62. inline bool Joystick::Down() { return !!(*Flags&J_D); }
  63. inline bool Joystick::Left() { return !!(*Flags&J_L); }
  64. inline bool Joystick::Right() { return !!(*Flags&J_R); }
  65.  
  66. inline bool Joystick::Trigger() { return !!(*Flags&128); }
  67.  
  68. extern int XDif[16];
  69. extern int YDif[16];
  70.  
  71. inline int Joystick::x() { return XDif[Way()]; }
  72. inline int Joystick::y() { return YDif[Way()]; }
  73.  
  74.  
  75. #endif
  76.