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"
7#include <SDL.h>
8
9namespace openmsx {
10
11class MSXEventDistributor;
12class StateChangeDistributor;
13class PluggingController;
14
15class JoyMega final
16#ifndef SDL_JOYSTICK_DISABLED
17 : public JoystickDevice, private MSXEventListener, private StateChangeListener
18#endif
19{
20public:
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()
29#ifndef SDL_JOYSTICK_DISABLED
30 override
31#endif
32 ;
33
34#ifndef SDL_JOYSTICK_DISABLED
35 // Pluggable
36 [[nodiscard]] std::string_view getName() const override;
37 [[nodiscard]] std::string_view getDescription() const override;
38 void plugHelper(Connector& connector, EmuTime::param time) override;
39 void unplugHelper(EmuTime::param time) override;
40
41 // JoystickDevice
42 [[nodiscard]] uint8_t read(EmuTime::param time) override;
43 void write(uint8_t value, EmuTime::param time) override;
44
45 template<typename Archive>
46 void serialize(Archive& ar, unsigned version);
47
48private:
49 void plugHelper2();
50 [[nodiscard]] unsigned calcInitialState();
51 void checkTime(EmuTime::param time);
52 void createEvent(EmuTime::param time, unsigned press, unsigned release);
53 void createEvent(EmuTime::param time, unsigned newStatus);
54
55 // MSXEventListener
56 void signalMSXEvent(const Event& event,
57 EmuTime::param time) noexcept override;
58 // StateChangeListener
59 void signalStateChange(const StateChange& event) override;
60 void stopReplay(EmuTime::param time) noexcept override;
61
62private:
63 MSXEventDistributor& eventDistributor;
64 StateChangeDistributor& stateChangeDistributor;
65
66 SDL_Joystick* const joystick;
67 const int joyNum;
68 const std::string name;
69 const std::string desc;
70
71 EmuTime lastTime;
72 unsigned status;
73 uint8_t cycle; // 0-7
74 uint8_t cycleMask; // 1 or 7
75#endif // SDL_JOYSTICK_DISABLED
76};
77
78} // namespace openmsx
79
80#endif
Represents something you can plug devices into.
Definition: Connector.hh:21
void unplugHelper(EmuTime::param time) override
Definition: JoyMega.cc:135
JoyMega(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, SDL_Joystick *joystick)
Definition: JoyMega.cc:86
uint8_t read(EmuTime::param time) override
Read from the joystick device.
Definition: JoyMega.cc:143
std::string_view getName() const override
Name used to identify this pluggable.
Definition: JoyMega.cc:109
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, PluggingController &controller)
Definition: JoyMega.cc:23
~JoyMega() override
Definition: JoyMega.cc:100
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: JoyMega.cc:119
std::string_view getDescription() const override
Description for this pluggable.
Definition: JoyMega.cc:114
void write(uint8_t value, EmuTime::param time) override
Write a value to the joystick device.
Definition: JoyMega.cc:173
void serialize(Archive &ar, unsigned version)
Definition: JoyMega.cc:317
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