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"
7#include "StringSetting.hh"
8#include "serialize_meta.hh"
9#include <SDL.h>
10
11namespace openmsx {
12
13class MSXEventDistributor;
14class StateChangeDistributor;
15class CommandController;
16class PluggingController;
17class GlobalSettings;
18class IntegerSetting;
19class TclObject;
20class Interpreter;
21
24class Joystick final
25#ifndef SDL_JOYSTICK_DISABLED
26 : public JoystickDevice, private MSXEventListener, private StateChangeListener
27#endif
28{
29public:
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()
44#ifndef SDL_JOYSTICK_DISABLED
45 override
46#endif
47 ;
48
49#ifndef SDL_JOYSTICK_DISABLED
50 // Pluggable
51 [[nodiscard]] std::string_view getName() const override;
52 [[nodiscard]] std::string_view getDescription() const override;
53 void plugHelper(Connector& connector, EmuTime::param time) override;
54 void unplugHelper(EmuTime::param time) override;
55
56 // JoystickDevice
57 [[nodiscard]] byte read(EmuTime::param time) override;
58 void write(byte value, EmuTime::param time) override;
59
60 template<typename Archive>
61 void serialize(Archive& ar, unsigned version);
62
63private:
64 void plugHelper2();
65 [[nodiscard]] byte calcState();
66 [[nodiscard]] bool getState(Interpreter& interp, const TclObject& dict, std::string_view key,
67 int threshold);
68 void createEvent(EmuTime::param time, byte newStatus);
69
70 // MSXEventListener
71 void signalMSXEvent(const Event& event,
72 EmuTime::param time) noexcept override;
73 // StateChangeListener
74 void signalStateChange(const StateChange& event) override;
75 void stopReplay(EmuTime::param time) noexcept override;
76
77private:
78 MSXEventDistributor& eventDistributor;
79 StateChangeDistributor& stateChangeDistributor;
80
81 SDL_Joystick* const joystick;
82 const unsigned joyNum;
83 IntegerSetting& deadSetting; // must come after joyNum
84 const std::string name;
85 const std::string desc;
86 StringSetting configSetting;
87
88 byte status;
89 bool pin8;
90#endif // SDL_JOYSTICK_DISABLED
91};
93
94} // namespace openmsx
95
96#endif
Represents something you can plug devices into.
Definition: Connector.hh:21
This class contains settings that are used by several other class (including some singletons).
A Setting with an integer value.
Uses an SDL joystick to emulate an MSX joystick.
Definition: Joystick.hh:28
std::string_view getName() const override
Name used to identify this pluggable.
Definition: Joystick.cc:184
void unplugHelper(EmuTime::param time) override
Definition: Joystick.cc:209
std::string_view getDescription() const override
Description for this pluggable.
Definition: Joystick.cc:189
~Joystick() override
Definition: Joystick.cc:173
void write(byte value, EmuTime::param time) override
Write a value to the joystick device.
Definition: Joystick.cc:222
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Joystick.cc:194
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, PluggingController &controller)
Register all available SDL joysticks.
Definition: Joystick.cc:23
void serialize(Archive &ar, unsigned version)
Definition: Joystick.cc:363
byte read(EmuTime::param time) override
Read from the joystick device.
Definition: Joystick.cc:217
Joystick(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, SDL_Joystick *joystick)
Definition: Joystick.cc:152
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
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)