OXYGENHUB
◆ main openmsx / src / input / MSXJoystick.hh
2.1 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef MSXJOYSTICK_HH
2
#define MSXJOYSTICK_HH
3
4
#include "JoystickDevice.hh"
5
6
#include "BooleanInput.hh"
7
#include "MSXEventListener.hh"
8
#include "StateChangeListener.hh"
9
#include "StringSetting.hh"
10
11
#include <array>
12
#include <vector>
13
14
namespace openmsx {
15
16
class CommandController;
17
class JoystickManager;
18
class MSXEventDistributor;
19
class StateChangeDistributor;
20
21
class MSXJoystick final : public JoystickDevice, private MSXEventListener
22
                        , private StateChangeListener
23
{
24
public:
25
	MSXJoystick(CommandController& commandController,
26
	            MSXEventDistributor& eventDistributor,
27
	            StateChangeDistributor& stateChangeDistributor,
28
	            JoystickManager& joystickManager,
29
	            uint8_t id);
30
	~MSXJoystick() override;
31
32
	[[nodiscard]] static TclObject getDefaultConfig(JoystickId joyId, const JoystickManager& joystickManager);
33
34
	template<typename Archive>
35
	void serialize(Archive& ar, unsigned version);
36
37
private:
38
	void checkJoystickConfig(const TclObject& newValue);
39
40
	// Pluggable
41
	[[nodiscard]] zstring_view getName() const override;
42
	[[nodiscard]] zstring_view getDescription() const override;
43
	void plugHelper(Connector& connector, EmuTime time) override;
44
	void unplugHelper(EmuTime time) override;
45
46
	// MSXJoystickDevice
47
	[[nodiscard]] uint8_t read(EmuTime time) override;
48
	void write(uint8_t value, EmuTime time) override;
49
50
	// MSXEventListener
51
	void signalMSXEvent(const Event& event,
52
	                    EmuTime time) noexcept override;
53
	// StateChangeListener
54
	void signalStateChange(const StateChange& event) override;
55
	void stopReplay(EmuTime time) noexcept override;
56
57
private:
58
	CommandController& commandController;
59
	MSXEventDistributor& eventDistributor;
60
	StateChangeDistributor& stateChangeDistributor;
61
	JoystickManager& joystickManager;
62
	StringSetting configSetting;
63
64
	// up, down, left, right, a, b (in sync with order in JoystickDevice)
65
	std::array<std::vector<BooleanInput>, 6> bindings; // calculated from 'configSetting'
66
67
	const std::string description;
68
	const uint8_t id;
69
	uint8_t status = JOY_UP | JOY_DOWN | JOY_LEFT | JOY_RIGHT |
70
	                 JOY_BUTTONA | JOY_BUTTONB;
71
	bool pin8;
72
};
73
74
} // namespace openmsx
75
76
#endif