Joystick.cpp
上传用户:luhy168
上传日期:2022-01-10
资源大小:240k
文件大小:1k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. // Joystick.cpp
  2. #include "Joystick.h"
  3. Joystick::Joystick(unsigned int PortValue)
  4. {
  5. if ((PortValue != 0x4016) || (PortValue != 0x4017))
  6. Port = 0x4016;
  7. else
  8. Port = PortValue;
  9. Strobe();
  10. }
  11. void Joystick::Strobe()
  12. {
  13. BitIndex = 0;
  14. }
  15. void Joystick::write(unsigned char value)
  16. {
  17. if (((value & 1) == 1) && (StrobeOnNext == false))
  18. StrobeOnNext = true;
  19. else if (((value & 1) == 0) && (StrobeOnNext == true))
  20. {
  21. Strobe();
  22. StrobeOnNext = false;
  23. }
  24. }
  25. unsigned char Joystick::read()
  26. {
  27. char BitReturn = BitStream[BitIndex];
  28. BitIndex++;
  29. // Check to see if read past the joysticks data.  Not likely that this
  30. // will happen but its possible.
  31. if (BitIndex >= 24)
  32. Strobe();
  33. return BitReturn;
  34. }
  35. char Joystick::GetButton(int button)
  36. {
  37. return BitStream[button];
  38. }
  39. void Joystick::SetButton(int button)
  40. {
  41. BitStream[button] = 1;
  42. }
  43. void Joystick::ClearButton(int button)
  44. {
  45. BitStream[button] = 0;
  46. }