openMSX
Joystick.hh
Go to the documentation of this file.
1 #ifndef JOYSTICK_HH
2 #define JOYSTICK_HH
3 
4 #include "JoystickDevice.hh"
5 #include "MSXEventListener.hh"
6 #include "StateChangeListener.hh"
7 #include "StringSetting.hh"
8 #include "serialize_meta.hh"
9 #include <SDL.h>
10 
11 namespace openmsx {
12 
13 class MSXEventDistributor;
14 class StateChangeDistributor;
15 class CommandController;
16 class PluggingController;
17 class GlobalSettings;
18 class IntegerSetting;
19 class TclObject;
20 class Interpreter;
21 
24 class Joystick final
25 #ifndef SDL_JOYSTICK_DISABLED
26  : public JoystickDevice, private MSXEventListener, private StateChangeListener
27 #endif
28 {
29 public:
32  static void registerAll(MSXEventDistributor& eventDistributor,
33  StateChangeDistributor& stateChangeDistributor,
34  CommandController& commandController,
35  GlobalSettings& globalSettings,
36  PluggingController& controller);
37 
38  Joystick(MSXEventDistributor& eventDistributor,
39  StateChangeDistributor& stateChangeDistributor,
40  CommandController& commandController,
41  GlobalSettings& globalSettings,
42  SDL_Joystick* joystick);
43  ~Joystick() override;
44 
45 #ifndef SDL_JOYSTICK_DISABLED
46  // Pluggable
47  const std::string& getName() const override;
48  std::string_view getDescription() const override;
49  void plugHelper(Connector& connector, EmuTime::param time) override;
50  void unplugHelper(EmuTime::param time) override;
51 
52  // JoystickDevice
53  byte read(EmuTime::param time) override;
54  void write(byte value, EmuTime::param time) override;
55 
56  template<typename Archive>
57  void serialize(Archive& ar, unsigned version);
58 
59 private:
60  void plugHelper2();
61  byte calcState();
62  bool getState(Interpreter& interp, const TclObject& dict, std::string_view key,
63  int threshold);
64  void createEvent(EmuTime::param time, byte newStatus);
65 
66  // MSXEventListener
67  void signalMSXEvent(const std::shared_ptr<const Event>& event,
68  EmuTime::param time) override;
69  // StateChangeListener
70  void signalStateChange(const std::shared_ptr<StateChange>& event) override;
71  void stopReplay(EmuTime::param time) override;
72 
73  MSXEventDistributor& eventDistributor;
74  StateChangeDistributor& stateChangeDistributor;
75 
76  SDL_Joystick* const joystick;
77  const unsigned joyNum;
78  IntegerSetting& deadSetting; // must come after joyNum
79  const std::string name;
80  const std::string desc;
81  StringSetting configSetting;
82 
83  byte status;
84  bool pin8;
85 #endif // SDL_JOYSTICK_DISABLED
86 };
88 
89 } // namespace openmsx
90 
91 #endif
openmsx::Joystick::serialize
void serialize(Archive &ar, unsigned version)
Definition: Joystick.cc:361
openmsx::Joystick::~Joystick
~Joystick() override
Definition: Joystick.cc:178
openmsx::CommandController
Definition: CommandController.hh:17
StateChangeListener.hh
openmsx::Joystick::write
void write(byte value, EmuTime::param time) override
Write a value to the joystick device.
Definition: Joystick.cc:227
openmsx::MSXEventDistributor
Definition: MSXEventDistributor.hh:13
openmsx::Joystick::getDescription
std::string_view getDescription() const override
Description for this pluggable.
Definition: Joystick.cc:194
serialize_meta.hh
openmsx::JoystickDevice
Definition: JoystickDevice.hh:9
openmsx::Joystick::unplugHelper
void unplugHelper(EmuTime::param time) override
Definition: Joystick.cc:214
openmsx::MSXEventListener
Definition: MSXEventListener.hh:11
openmsx::StateChangeDistributor
Definition: StateChangeDistributor.hh:14
openmsx::Joystick::read
byte read(EmuTime::param time) override
Read from the joystick device.
Definition: Joystick.cc:222
JoystickDevice.hh
openmsx::Joystick::registerAll
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, PluggingController &controller)
Register all available SDL joysticks.
Definition: Joystick.cc:25
StringSetting.hh
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::Joystick::getName
const std::string & getName() const override
Name used to identify this pluggable.
Definition: Joystick.cc:189
openmsx::StringSetting
Definition: StringSetting.hh:8
MSXEventListener.hh
openmsx::Joystick::Joystick
Joystick(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, SDL_Joystick *joystick)
Definition: Joystick.cc:156
openmsx::Joystick::plugHelper
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Joystick.cc:199
openmsx::Joystick
Uses an SDL joystick to emulate an MSX joystick.
Definition: Joystick.hh:24
openmsx::GlobalSettings
This class contains settings that are used by several other class (including some singletons).
Definition: GlobalSettings.hh:23
openmsx::IntegerSetting
A Setting with an integer value.
Definition: IntegerSetting.hh:10
openmsx::Connector
Represents something you can plug devices into.
Definition: Connector.hh:20
openmsx::TclObject
Definition: TclObject.hh:21
openmsx::PluggingController
Central administration of Connectors and Pluggables.
Definition: PluggingController.hh:21
openmsx::Interpreter
Definition: Interpreter.hh:16
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::StateChangeListener
Definition: StateChangeListener.hh:11