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  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
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: JoyMega.cc:123
void serialize(Archive &ar, unsigned version)
Definition: JoyMega.cc:329
Represents something you can plug devices into.
Definition: Connector.hh:20
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, PluggingController &controller)
Definition: JoyMega.cc:26
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
Central administration of Connectors and Pluggables.
JoyMega(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, SDL_Joystick *joystick)
Definition: JoyMega.cc:90
void write(byte value, EmuTime::param time) override
Write a value to the joystick device.
Definition: JoyMega.cc:177
void unplugHelper(EmuTime::param time) override
Definition: JoyMega.cc:139
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
~JoyMega() override
Definition: JoyMega.cc:104
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
string_view getDescription() const override
Description for this pluggable.
Definition: JoyMega.cc:118
byte read(EmuTime::param time) override
Read from the joystick device.
Definition: JoyMega.cc:147
const std::string & getName() const override
Name used to identify this pluggable.
Definition: JoyMega.cc:113