openMSX
JoystickPort.hh
Go to the documentation of this file.
1 #ifndef JOYSTICKPORT_HH
2 #define JOYSTICKPORT_HH
3 
4 #include "Connector.hh"
5 #include "openmsx.hh"
6 #include "static_string_view.hh"
7 
8 namespace openmsx {
9 
10 class JoystickDevice;
11 class PluggingController;
12 
14 {
15 public:
16  virtual ~JoystickPortIf() = default;
17  [[nodiscard]] virtual byte read(EmuTime::param time) = 0;
18  virtual void write(byte value, EmuTime::param time) = 0;
19 protected:
20  JoystickPortIf() = default;
21 };
22 
23 class JoystickPort final : public JoystickPortIf, public Connector
24 {
25 public:
26  JoystickPort(PluggingController& pluggingController,
27  std::string name, static_string_view description);
28 
29  [[nodiscard]] JoystickDevice& getPluggedJoyDev() const;
30 
31  // Connector
32  [[nodiscard]] std::string_view getDescription() const override;
33  [[nodiscard]] std::string_view getClass() const override;
34  void plug(Pluggable& device, EmuTime::param time) override;
35 
36  [[nodiscard]] byte read(EmuTime::param time) override;
37  void write(byte value, EmuTime::param time) override;
38 
39  template<typename Archive>
40  void serialize(Archive& ar, unsigned version);
41 
42 private:
43  void writeDirect(byte value, EmuTime::param time);
44 
45 private:
46  byte lastValue;
47  const static_string_view description;
48 };
49 
50 class DummyJoystickPort final : public JoystickPortIf
51 {
52 public:
53  [[nodiscard]] byte read(EmuTime::param time) override;
54  void write(byte value, EmuTime::param time) override;
55 };
56 
57 } // namespace openmsx
58 
59 #endif
Represents something you can plug devices into.
Definition: Connector.hh:21
void write(byte value, EmuTime::param time) override
Definition: JoystickPort.cc:76
byte read(EmuTime::param time) override
Definition: JoystickPort.cc:71
virtual ~JoystickPortIf()=default
virtual void write(byte value, EmuTime::param time)=0
virtual byte read(EmuTime::param time)=0
byte read(EmuTime::param time) override
Definition: JoystickPort.cc:40
JoystickPort(PluggingController &pluggingController, std::string name, static_string_view description)
Definition: JoystickPort.cc:11
JoystickDevice & getPluggedJoyDev() const
Definition: JoystickPort.cc:29
std::string_view getDescription() const override
Get a description for this connector.
Definition: JoystickPort.cc:19
void serialize(Archive &ar, unsigned version)
Definition: JoystickPort.cc:56
void write(byte value, EmuTime::param time) override
Definition: JoystickPort.cc:45
void plug(Pluggable &device, EmuTime::param time) override
This plugs a Pluggable in this Connector.
Definition: JoystickPort.cc:34
std::string_view getClass() const override
A Connector belong to a certain class.
Definition: JoystickPort.cc:24
Central administration of Connectors and Pluggables.
static_string_view
This file implemented 3 utility functions:
Definition: Autofire.cc:9