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