OXYGENHUB
◆ main openmsx / src / cassette / CassettePort.hh
3.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef CASSETTEPORT_HH
2
#define CASSETTEPORT_HH
3
4
#include "CassettePlayerCommand.hh"
5
6
#include "Connector.hh"
7
#include "serialize_meta.hh"
8
9
#include "components.hh"
10
11
namespace openmsx {
12
13
class HardwareConfig;
14
class MSXMotherBoard;
15
class CassetteDevice;
16
class CassettePlayer;
17
#if COMPONENT_LASERDISC
18
class LaserdiscPlayer;
19
#endif
20
21
class CassettePortInterface
22
{
23
public:
24
	virtual ~CassettePortInterface() = default;
25
26
	/**
27
	* Sets the cassette motor relay
28
	*  false = off   true = on
29
	*/
30
	virtual void setMotor(bool status, EmuTime time) = 0;
31
32
	/**
33
	* Writes one bit to the cassette port.
34
	* From the RedBook:
35
	*   The CasOut bit is filtered and attenuated before being
36
	*   taken to the cassette DIN socket as the MIC signal. All
37
	*   cassette tone generation is performed in software.
38
	*/
39
	virtual void cassetteOut(bool output, EmuTime time) = 0;
40
41
	/**
42
	 * last bit written to CasOut.
43
	 * for use in Pluggable::plugHelper()
44
	 */
45
	[[nodiscard]] virtual bool lastOut() const = 0;
46
47
	/**
48
	* Reads one bit from the cassette port.
49
	* From the RedBook:
50
	*   The cassette input is used to read the signal from the
51
	*   cassette EAR output. This is passed through a comparator
52
	*   to clean the edges and to convert to digital levels,
53
	*   but is otherwise unprocessed.
54
	*/
55
	virtual bool cassetteIn(EmuTime time) = 0;
56
57
#if COMPONENT_LASERDISC
58
	/**
59
	* Set the Laserdisc Player; when the motor control is off, sound
60
	* is read from the laserdisc.
61
	*/
62
	virtual void setLaserdiscPlayer(LaserdiscPlayer *laserdisc) = 0;
63
#endif
64
65
	/**
66
	* Get the cassette player (if available)
67
	*/
68
	virtual CassettePlayer* getCassettePlayer() = 0;
69
};
70
71
class CassettePort final : public CassettePortInterface, public Connector
72
{
73
public:
74
	explicit CassettePort(HardwareConfig& hwConf);
75
	~CassettePort() override;
76
	void setMotor(bool status, EmuTime time) override;
77
	void cassetteOut(bool output, EmuTime time) override;
78
	bool cassetteIn(EmuTime time) override;
79
#if COMPONENT_LASERDISC
80
	void setLaserdiscPlayer(LaserdiscPlayer* laserdisc) override;
81
#endif
82
	[[nodiscard]] bool lastOut() const override;
83
	CassettePlayer* getCassettePlayer() override { return cassettePlayer; }
84
85
	// Connector
86
	[[nodiscard]] zstring_view getDescription() const override;
87
	[[nodiscard]] zstring_view getClass() const override;
88
89
	template<typename Archive>
90
	void serialize(Archive& ar, unsigned version);
91
92
private:
93
	[[nodiscard]] CassetteDevice& getPluggedCasDev() const;
94
95
	MSXMotherBoard& motherBoard;
96
97
#if COMPONENT_LASERDISC
98
	LaserdiscPlayer* laserdiscPlayer = nullptr;
99
#endif
100
	CassettePlayer* cassettePlayer;
101
102
	bool lastOutput = false;
103
	bool motorControl = false;
104
};
105
SERIALIZE_CLASS_VERSION(CassettePort, 2);
106
107
class DummyCassettePort final : public CassettePortInterface
108
{
109
public:
110
	explicit DummyCassettePort(MSXMotherBoard& motherBoard);
111
	void setMotor(bool status, EmuTime time) override;
112
	void cassetteOut(bool output, EmuTime time) override;
113
	bool cassetteIn(EmuTime time) override;
114
#if COMPONENT_LASERDISC
115
	void setLaserdiscPlayer(LaserdiscPlayer *laserdisc) override;
116
#endif
117
	[[nodiscard]] bool lastOut() const override;
118
	CassettePlayer* getCassettePlayer() override { return nullptr; }
119
private:
120
	CassettePlayerCommand cassettePlayerCommand;
121
};
122
123
} // namespace openmsx
124
125
#endif