home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gchsrc31 / atarilib / joystick.cc < prev    next >
C/C++ Source or Header  |  1992-04-27  |  1KB  |  62 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. #include <osbind.h>
  13. #include "Joystick.h"
  14. #include "JoyISR.h"
  15.  
  16. /* GLOBAL */ volatile int JoyFlags[2]={0,0};
  17.  
  18. const char JoyJoyString[]="\024";
  19. const char MouseJoyString[]="\010";
  20.  
  21. int XDif[16] = { 0,0,0,0,-1,-1,-1,-1,1,1,1,1,0,0,0,0 };
  22. int YDif[16] = { 0,-1,1,0,0,-1,1,0,0,-1,1,0,0,-1,1,0 };
  23.  
  24. static int Enabled[2];
  25. static void* OldJoy;
  26.  
  27. Joystick::Joystick(int port=1)
  28. {
  29.     if (port==0 || port==1) {
  30.         if (!Enabled[port]) {
  31.             if (!Enabled[1-port]) {
  32.                 // Very first!
  33.                 _KBDVECS * KV=Kbdvbase();
  34.                 OldJoy=KV->joyvec;
  35.                 KV->joyvec=JoyISR;
  36.             }
  37.             if (port==0) Ikbdws(0,JoyJoyString);
  38.         }
  39.  
  40.         Enabled[port]++;
  41.         Flags=&JoyFlags[port];
  42.     } else {
  43.         // What shall we do with the drunken sailor?
  44.     }
  45. }
  46.  
  47. Joystick::~Joystick()
  48. {
  49.     int port=Flags==&JoyFlags[1]; // Resurect "port" from init
  50.  
  51.     Enabled[port]--;
  52.  
  53.     if (!Enabled[port]) {
  54.         if (!Enabled[1-port]) {
  55.             // Very last!
  56.             _KBDVECS * KV=Kbdvbase();
  57.             KV->joyvec=OldJoy;
  58.         }
  59.         if (port==0) Ikbdws(0,MouseJoyString);
  60.     }
  61. }
  62.