input.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. class Input {
  2. public:
  3. enum Device {
  4. DeviceNone,
  5. DeviceJoypad,
  6. DeviceMultitap,
  7. DeviceMouse,
  8. DeviceSuperScope,
  9. DeviceJustifier,
  10. DeviceJustifiers,
  11. };
  12. enum DeviceID {
  13. DeviceIDNone,
  14. DeviceIDJoypad1,
  15. DeviceIDJoypad2,
  16. DeviceIDMultitap1A,
  17. DeviceIDMultitap1B,
  18. DeviceIDMultitap1C,
  19. DeviceIDMultitap1D,
  20. DeviceIDMultitap2A,
  21. DeviceIDMultitap2B,
  22. DeviceIDMultitap2C,
  23. DeviceIDMultitap2D,
  24. DeviceIDMouse1,
  25. DeviceIDMouse2,
  26. DeviceIDSuperScope,
  27. DeviceIDJustifier1,
  28. DeviceIDJustifier2,
  29. };
  30. enum JoypadID {
  31. JoypadB = 0, JoypadY = 1,
  32. JoypadSelect = 2, JoypadStart = 3,
  33. JoypadUp = 4, JoypadDown = 5,
  34. JoypadLeft = 6, JoypadRight = 7,
  35. JoypadA = 8, JoypadX = 9,
  36. JoypadL = 10, JoypadR = 11,
  37. };
  38. enum MouseID {
  39. MouseX = 0, MouseY = 1,
  40. MouseLeft = 2, MouseRight = 3,
  41. };
  42. enum SuperScopeID {
  43. SuperScopeX = 0, SuperScopeY = 1,
  44. SuperScopeTrigger = 2, SuperScopeCursor = 3,
  45. SuperScopeTurbo = 4, SuperScopePause = 5,
  46. };
  47. enum JustifierID {
  48. JustifierX = 0, JustifierY = 1,
  49. JustifierTrigger = 2, JustifierStart = 3,
  50. };
  51. uint8 port_read(bool port);
  52. void port_set_device(bool port, unsigned device);
  53. void init();
  54. void poll();
  55. void update();
  56. //light guns (Super Scope, Justifier(s)) strobe IOBit whenever the CRT
  57. //beam cannon is detected. this needs to be tested at the cycle level
  58. //(hence inlining here for speed) to avoid 'dead space' during DRAM refresh.
  59. //iobit is updated during port_set_device(),
  60. //latchx, latchy are updated during update() (once per frame)
  61. alwaysinline void tick() {
  62. //only test if Super Scope or Justifier is connected
  63. if(iobit) {
  64. if(ppu.vcounter() == latchy //test Y cursor position
  65. && ppu.hcounter() == latchx << 2 //test X cursor position (cycles == pixels << 2)
  66. && latchy < (ppu.overscan() ? 240 : 225) //verify Y is not offscreen
  67. && latchx < 256 //verify X is not offscreen
  68. ) ppu.latch_counters();
  69. }
  70. }
  71. struct port_t {
  72. unsigned device;
  73. unsigned counter0; //read counters
  74. unsigned counter1;
  75. struct superscope_t {
  76. int x, y;
  77. bool trigger;
  78. bool cursor;
  79. bool turbo;
  80. bool pause;
  81. bool offscreen;
  82. bool turbolock;
  83. bool triggerlock;
  84. bool pauselock;
  85. } superscope;
  86. struct justifier_t {
  87. bool active;
  88. int x1, x2;
  89. int y1, y2;
  90. bool trigger1, trigger2;
  91. bool start1, start2;
  92. } justifier;
  93. } port[2];
  94. private:
  95. bool iobit;
  96. uint16_t latchx, latchy;
  97. friend class SNES;
  98. } input;