OXYGENHUB
◆ main openmsx / src / input / JoyMega.hh
2.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef JOYMEGA_HH
2
#define JOYMEGA_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 JoyMega final : public JoystickDevice, private MSXEventListener
22
                    , private StateChangeListener
23
{
24
public:
25
	JoyMega(CommandController& commandController,
26
	        MSXEventDistributor& eventDistributor,
27
	        StateChangeDistributor& stateChangeDistributor,
28
	        JoystickManager& joystickManager,
29
	        uint8_t id);
30
	~JoyMega() 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
	// JoystickDevice
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
	void plugHelper2();
58
	void checkTime(EmuTime time);
59
60
private:
61
	CommandController& commandController;
62
	MSXEventDistributor& eventDistributor;
63
	StateChangeDistributor& stateChangeDistributor;
64
	JoystickManager& joystickManager;
65
	StringSetting configSetting;
66
67
	// 0...3 :  up, down, left, right
68
	// 4...7 :  a, b, c, start
69
	// 8..11 :  x, y, z, select
70
	std::array<std::vector<BooleanInput>, 12> bindings; // calculated from 'configSetting'
71
72
	const std::string description;
73
	EmuTime lastTime = EmuTime::zero();
74
	unsigned status = 0xfff;
75
	uint8_t cycle; // 0-7
76
	uint8_t cycleMask; // 1 or 7
77
	const uint8_t id;
78
};
79
80
} // namespace openmsx
81
82
#endif