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() override;
29 
30 #ifndef SDL_JOYSTICK_DISABLED
31  // Pluggable
32  const std::string& getName() const override;
33  std::string_view getDescription() const override;
34  void plugHelper(Connector& connector, EmuTime::param time) override;
35  void unplugHelper(EmuTime::param time) override;
36 
37  // JoystickDevice
38  byte read(EmuTime::param time) override;
39  void write(byte value, EmuTime::param time) override;
40 
41  template<typename Archive>
42  void serialize(Archive& ar, unsigned version);
43 
44 private:
45  void plugHelper2();
46  unsigned calcInitialState();
47  void checkTime(EmuTime::param time);
48  void createEvent(EmuTime::param time, unsigned press, unsigned release);
49  void createEvent(EmuTime::param time, unsigned newStatus);
50 
51  // MSXEventListener
52  void signalMSXEvent(const std::shared_ptr<const Event>& event,
53  EmuTime::param time) override;
54  // StateChangeListener
55  void signalStateChange(const std::shared_ptr<StateChange>& event) override;
56  void stopReplay(EmuTime::param time) override;
57 
58  MSXEventDistributor& eventDistributor;
59  StateChangeDistributor& stateChangeDistributor;
60 
61  SDL_Joystick* const joystick;
62  const unsigned joyNum;
63  const std::string name;
64  const std::string desc;
65 
66  EmuTime lastTime;
67  unsigned status;
68  byte cycle; // 0-7
69  byte cycleMask; // 1 or 7
70 #endif // SDL_JOYSTICK_DISABLED
71 };
72 
73 } // namespace openmsx
74 
75 #endif
openmsx::JoyMega::write
void write(byte value, EmuTime::param time) override
Write a value to the joystick device.
Definition: JoyMega.cc:177
openmsx::JoyMega::serialize
void serialize(Archive &ar, unsigned version)
Definition: JoyMega.cc:329
openmsx::JoyMega::JoyMega
JoyMega(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, SDL_Joystick *joystick)
Definition: JoyMega.cc:90
StateChangeListener.hh
openmsx::MSXEventDistributor
Definition: MSXEventDistributor.hh:13
openmsx::JoystickDevice
Definition: JoystickDevice.hh:9
openmsx::MSXEventListener
Definition: MSXEventListener.hh:11
openmsx::StateChangeDistributor
Definition: StateChangeDistributor.hh:14
JoystickDevice.hh
openmsx::JoyMega::~JoyMega
~JoyMega() override
Definition: JoyMega.cc:104
MSXEventListener.hh
openmsx::JoyMega::plugHelper
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: JoyMega.cc:123
openmsx::JoyMega
Definition: JoyMega.hh:15
openmsx::JoyMega::unplugHelper
void unplugHelper(EmuTime::param time) override
Definition: JoyMega.cc:139
openmsx::JoyMega::read
byte read(EmuTime::param time) override
Read from the joystick device.
Definition: JoyMega.cc:147
openmsx::Connector
Represents something you can plug devices into.
Definition: Connector.hh:20
openmsx::JoyMega::getName
const std::string & getName() const override
Name used to identify this pluggable.
Definition: JoyMega.cc:113
openmsx::PluggingController
Central administration of Connectors and Pluggables.
Definition: PluggingController.hh:21
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::JoyMega::registerAll
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, PluggingController &controller)
Definition: JoyMega.cc:26
openmsx::StateChangeListener
Definition: StateChangeListener.hh:11
openmsx::JoyMega::getDescription
std::string_view getDescription() const override
Description for this pluggable.
Definition: JoyMega.cc:118