openMSX
CassettePort.cc
Go to the documentation of this file.
1 #include "CassettePort.hh"
2 #include "CassetteDevice.hh"
3 #include "CassettePlayer.hh"
4 #include "components.hh"
5 #if COMPONENT_LASERDISC
6 #include "LaserdiscPlayer.hh"
7 #endif
8 #include "DummyCassetteDevice.hh"
9 #include "HardwareConfig.hh"
10 #include "MSXMotherBoard.hh"
11 #include "PluggingController.hh"
12 #include "checked_cast.hh"
13 #include "serialize.hh"
14 #include <memory>
15 
16 namespace openmsx {
17 
18 // DummyCassettePort
19 
20 void DummyCassettePort::setMotor(bool /*status*/, EmuTime::param /*time*/)
21 {
22  // do nothing
23 }
24 void DummyCassettePort::cassetteOut(bool /*output*/, EmuTime::param /*time*/)
25 {
26  // do nothing
27 }
28 bool DummyCassettePort::cassetteIn(EmuTime::param /*time*/)
29 {
30  return false;
31 }
33 {
34  return false; // not relevant
35 }
36 #if COMPONENT_LASERDISC
38 {
39  // do nothing
40 }
41 #endif
42 
43 
44 // CassettePort
45 
47  : Connector(hwConf.getMotherBoard().getPluggingController(), "cassetteport",
48  std::make_unique<DummyCassetteDevice>())
49  , motherBoard(hwConf.getMotherBoard())
51  , laserdiscPlayer(nullptr)
52 #endif
53  , lastOutput(false)
54  , motorControl(false)
55 {
56  auto player = std::make_unique<CassettePlayer>(hwConf);
57  cassettePlayer = player.get();
58  getPluggingController().registerPluggable(std::move(player));
59 }
60 
62 {
63  unplug(motherBoard.getCurrentTime());
64 }
65 
66 
67 void CassettePort::setMotor(bool status, EmuTime::param time)
68 {
69  // TODO make 'click' sound
70  motorControl = status;
71  getPluggedCasDev().setMotor(status, time);
72 }
73 
74 void CassettePort::cassetteOut(bool output, EmuTime::param time)
75 {
76  lastOutput = output;
77  // leave everything to the pluggable
78  getPluggedCasDev().setSignal(output, time);
79 }
80 
82 {
83  return lastOutput;
84 }
85 
86 bool CassettePort::cassetteIn(EmuTime::param time)
87 {
88  // All analog filtering is ignored for now
89  // only important component is DC-removal
90  // we just assume sample has no DC component
91  int16_t sample;
92 #if COMPONENT_LASERDISC
93  if (!motorControl && laserdiscPlayer) {
94  sample = laserdiscPlayer->readSample(time);
95  } else
96 #endif
97  {
98  sample = getPluggedCasDev().readSample(time); // read 1 sample
99  }
100  bool result = (sample >= 0); // comparator
101  return result;
102 }
103 
104 #if COMPONENT_LASERDISC
106 {
107  laserdiscPlayer = laserdiscPlayer_;
108 }
109 #endif
110 
111 void CassettePort::unplug(EmuTime::param time)
112 {
113  Connector::unplug(time);
114 }
115 
116 std::string_view CassettePort::getDescription() const
117 {
118  return "MSX Cassette port";
119 }
120 
121 std::string_view CassettePort::getClass() const
122 {
123  return "Cassette Port";
124 }
125 
126 CassetteDevice& CassettePort::getPluggedCasDev() const
127 {
128  return *checked_cast<CassetteDevice*>(&getPlugged());
129 }
130 
131 template<typename Archive>
132 void CassettePort::serialize(Archive& ar, unsigned version)
133 {
134  ar.template serializeBase<Connector>(*this);
135  // don't serialize 'lastOutput', done via MSXPPI
136 
137  // Must come after serialization of the connector because that one
138  // potentionally serializes the CassettePlayer.
139  if (ar.versionAtLeast(version, 2)) {
140  // always serialize CassettePlayer, even if it's not plugged in.
141  ar.serializeOnlyOnce("cassettePlayer", *cassettePlayer);
142  }
143 }
145 
146 } // namespace openmsx
virtual int16_t readSample(EmuTime::param time)=0
Read wave data from cassette device.
virtual void setSignal(bool output, EmuTime::param time)=0
Sets the cassette output signal false = low true = high.
virtual void setMotor(bool status, EmuTime::param time)=0
Sets the cassette motor relay false = off true = on.
bool cassetteIn(EmuTime::param time) override
Reads one bit from the cassette port.
Definition: CassettePort.cc:86
void cassetteOut(bool output, EmuTime::param time) override
Writes one bit to the cassette port.
Definition: CassettePort.cc:74
bool lastOut() const override
last bit written to CasOut.
Definition: CassettePort.cc:81
void unplug(EmuTime::param time) override
This unplugs the currently inserted Pluggable from this Connector.
void serialize(Archive &ar, unsigned version)
~CassettePort() override
Definition: CassettePort.cc:61
std::string_view getClass() const override
A Connector belong to a certain class.
CassettePort(const HardwareConfig &hwConf)
Definition: CassettePort.cc:46
void setLaserdiscPlayer(LaserdiscPlayer *laserdisc) override
Set the Laserdisc Player; when the motor control is off, sound is read from the laserdisc.
void setMotor(bool status, EmuTime::param time) override
Sets the cassette motor relay false = off true = on.
Definition: CassettePort.cc:67
std::string_view getDescription() const override
Get a description for this connector.
Represents something you can plug devices into.
Definition: Connector.hh:21
Pluggable & getPlugged() const
Returns the Pluggable currently plugged in.
Definition: Connector.hh:59
virtual void unplug(EmuTime::param time)
This unplugs the currently inserted Pluggable from this Connector.
Definition: Connector.cc:31
PluggingController & getPluggingController() const
Definition: Connector.hh:61
bool lastOut() const override
last bit written to CasOut.
Definition: CassettePort.cc:32
void setLaserdiscPlayer(LaserdiscPlayer *laserdisc) override
Set the Laserdisc Player; when the motor control is off, sound is read from the laserdisc.
Definition: CassettePort.cc:37
bool cassetteIn(EmuTime::param time) override
Reads one bit from the cassette port.
Definition: CassettePort.cc:28
void cassetteOut(bool output, EmuTime::param time) override
Writes one bit to the cassette port.
Definition: CassettePort.cc:24
void setMotor(bool status, EmuTime::param time) override
Sets the cassette motor relay false = off true = on.
Definition: CassettePort.cc:20
int16_t readSample(EmuTime::param time)
EmuTime::param getCurrentTime()
Convenience method: This is the same as getScheduler().getCurrentTime().
void registerPluggable(std::unique_ptr< Pluggable > pluggable)
Add a Pluggable to the registry.
#define COMPONENT_LASERDISC
Definition: components.hh:8
This file implemented 3 utility functions:
Definition: Autofire.cc:9
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:998