openMSX
JoyMega.hh
Go to the documentation of this file.
1 #ifndef JOYMEGA_HH
2 #define JOYMEGA_HH
3 
4 #include "JoystickDevice.hh"
5 #include "MSXEventListener.hh"
6 #include "StateChangeListener.hh"
7 #include <SDL.h>
8 
9 namespace openmsx {
10 
11 class MSXEventDistributor;
12 class StateChangeDistributor;
13 class PluggingController;
14 
15 class JoyMega final
16 #ifndef SDL_JOYSTICK_DISABLED
17  : public JoystickDevice, private MSXEventListener, private StateChangeListener
18 #endif
19 {
20 public:
21  static void registerAll(MSXEventDistributor& eventDistributor,
22  StateChangeDistributor& stateChangeDistributor,
23  PluggingController& controller);
24 
25  JoyMega(MSXEventDistributor& eventDistributor,
26  StateChangeDistributor& stateChangeDistributor,
27  SDL_Joystick* joystick);
28  ~JoyMega()
29 #ifndef SDL_JOYSTICK_DISABLED
30  override
31 #endif
32  ;
33 
34 #ifndef SDL_JOYSTICK_DISABLED
35  // Pluggable
36  [[nodiscard]] std::string_view getName() const override;
37  [[nodiscard]] std::string_view getDescription() const override;
38  void plugHelper(Connector& connector, EmuTime::param time) override;
39  void unplugHelper(EmuTime::param time) override;
40 
41  // JoystickDevice
42  [[nodiscard]] byte read(EmuTime::param time) override;
43  void write(byte value, EmuTime::param time) override;
44 
45  template<typename Archive>
46  void serialize(Archive& ar, unsigned version);
47 
48 private:
49  void plugHelper2();
50  [[nodiscard]] unsigned calcInitialState();
51  void checkTime(EmuTime::param time);
52  void createEvent(EmuTime::param time, unsigned press, unsigned release);
53  void createEvent(EmuTime::param time, unsigned newStatus);
54 
55  // MSXEventListener
56  void signalMSXEvent(const Event& event,
57  EmuTime::param time) noexcept override;
58  // StateChangeListener
59  void signalStateChange(const StateChange& event) override;
60  void stopReplay(EmuTime::param time) noexcept override;
61 
62 private:
63  MSXEventDistributor& eventDistributor;
64  StateChangeDistributor& stateChangeDistributor;
65 
66  SDL_Joystick* const joystick;
67  const unsigned joyNum;
68  const std::string name;
69  const std::string desc;
70 
71  EmuTime lastTime;
72  unsigned status;
73  byte cycle; // 0-7
74  byte cycleMask; // 1 or 7
75 #endif // SDL_JOYSTICK_DISABLED
76 };
77 
78 } // namespace openmsx
79 
80 #endif
Represents something you can plug devices into.
Definition: Connector.hh:21
void unplugHelper(EmuTime::param time) override
Definition: JoyMega.cc:135
JoyMega(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, SDL_Joystick *joystick)
Definition: JoyMega.cc:86
byte read(EmuTime::param time) override
Read from the joystick device.
Definition: JoyMega.cc:143
std::string_view getName() const override
Name used to identify this pluggable.
Definition: JoyMega.cc:109
void write(byte value, EmuTime::param time) override
Write a value to the joystick device.
Definition: JoyMega.cc:173
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, PluggingController &controller)
Definition: JoyMega.cc:23
~JoyMega() override
Definition: JoyMega.cc:100
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: JoyMega.cc:119
std::string_view getDescription() const override
Description for this pluggable.
Definition: JoyMega.cc:114
void serialize(Archive &ar, unsigned version)
Definition: JoyMega.cc:317
Central administration of Connectors and Pluggables.
Base class for all external MSX state changing events.
Definition: StateChange.hh:20
This file implemented 3 utility functions:
Definition: Autofire.cc:9