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
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
16namespace openmsx {
17
18// DummyCassettePort
19
20void DummyCassettePort::setMotor(bool /*status*/, EmuTime::param /*time*/)
21{
22 // do nothing
23}
24void DummyCassettePort::cassetteOut(bool /*output*/, EmuTime::param /*time*/)
25{
26 // do nothing
27}
28bool DummyCassettePort::cassetteIn(EmuTime::param /*time*/)
29{
30 return false;
31}
33{
34 return false; // not relevant
35}
36#if COMPONENT_LASERDISC
37void DummyCassettePort::setLaserdiscPlayer(LaserdiscPlayer* /* 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())
50{
51 auto player = std::make_unique<CassettePlayer>(hwConf);
52 cassettePlayer = player.get();
53 getPluggingController().registerPluggable(std::move(player));
54}
55
60
61
62void CassettePort::setMotor(bool status, EmuTime::param time)
63{
64 // TODO make 'click' sound
65 motorControl = status;
66 getPluggedCasDev().setMotor(status, time);
67}
68
69void CassettePort::cassetteOut(bool output, EmuTime::param time)
70{
71 lastOutput = output;
72 // leave everything to the pluggable
73 getPluggedCasDev().setSignal(output, time);
74}
75
77{
78 return lastOutput;
79}
80
81bool CassettePort::cassetteIn(EmuTime::param time)
82{
83 // All analog filtering is ignored for now
84 // only important component is DC-removal
85 // we just assume sample has no DC component
86 int16_t sample = [&]{
87 #if COMPONENT_LASERDISC
88 if (!motorControl && laserdiscPlayer) {
89 return laserdiscPlayer->readSample(time);
90 }
91 #endif
92 return getPluggedCasDev().readSample(time); // read 1 sample
93 }();
94 return sample >= 0; // comparator
95}
96
97#if COMPONENT_LASERDISC
98void CassettePort::setLaserdiscPlayer(LaserdiscPlayer *laserdiscPlayer_)
99{
100 laserdiscPlayer = laserdiscPlayer_;
101}
102#endif
103
104std::string_view CassettePort::getDescription() const
105{
106 return "MSX Cassette port";
107}
108
109std::string_view CassettePort::getClass() const
110{
111 return "Cassette Port";
112}
113
114CassetteDevice& CassettePort::getPluggedCasDev() const
115{
116 return *checked_cast<CassetteDevice*>(&getPlugged());
117}
118
119template<typename Archive>
120void CassettePort::serialize(Archive& ar, unsigned version)
121{
122 ar.template serializeBase<Connector>(*this);
123 // don't serialize 'lastOutput', done via MSXPPI
124
125 // Must come after serialization of the connector because that one
126 // potentially serializes the CassettePlayer.
127 if (ar.versionAtLeast(version, 2)) {
128 // always serialize CassettePlayer, even if it's not plugged in.
129 ar.serializeOnlyOnce("cassettePlayer", *cassettePlayer);
130 }
131}
133
134} // 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.
void cassetteOut(bool output, EmuTime::param time) override
Writes one bit to the cassette port.
bool lastOut() const override
last bit written to CasOut.
void serialize(Archive &ar, unsigned version)
std::string_view getClass() const override
A Connector belong to a certain class.
CassettePort(const HardwareConfig &hwConf)
void setMotor(bool status, EmuTime::param time) override
Sets the cassette motor relay false = off true = on.
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.
bool cassetteIn(EmuTime::param time) override
Reads one bit from the cassette port.
void cassetteOut(bool output, EmuTime::param time) override
Writes one bit to the cassette port.
void setMotor(bool status, EmuTime::param time) override
Sets the cassette motor relay false = off true = on.
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
void registerPluggable(std::unique_ptr< Pluggable > pluggable)
Add a Pluggable to the registry.
This file implemented 3 utility functions:
Definition Autofire.cc:11
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)