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
21 : cassettePlayerCommand(
22 nullptr,
23 motherBoard.getCommandController(),
24 motherBoard.getStateChangeDistributor(),
25 motherBoard.getScheduler())
26{
27}
28
29void DummyCassettePort::setMotor(bool /*status*/, EmuTime::param /*time*/)
30{
31 // do nothing
32}
33void DummyCassettePort::cassetteOut(bool /*output*/, EmuTime::param /*time*/)
34{
35 // do nothing
36}
37bool DummyCassettePort::cassetteIn(EmuTime::param /*time*/)
38{
39 return false;
40}
42{
43 return false; // not relevant
44}
45#if COMPONENT_LASERDISC
46void DummyCassettePort::setLaserdiscPlayer(LaserdiscPlayer* /* laserdisc */)
47{
48 // do nothing
49}
50#endif
51
52
53// CassettePort
54
56 : Connector(hwConf.getMotherBoard().getPluggingController(), "cassetteport",
57 std::make_unique<DummyCassetteDevice>())
58 , motherBoard(hwConf.getMotherBoard())
59{
60 auto player = std::make_unique<CassettePlayer>(hwConf);
61 cassettePlayer = player.get();
62 getPluggingController().registerPluggable(std::move(player));
63}
64
69
70
71void CassettePort::setMotor(bool status, EmuTime::param time)
72{
73 // TODO make 'click' sound
74 motorControl = status;
75 getPluggedCasDev().setMotor(status, time);
76}
77
78void CassettePort::cassetteOut(bool output, EmuTime::param time)
79{
80 lastOutput = output;
81 // leave everything to the pluggable
82 getPluggedCasDev().setSignal(output, time);
83}
84
86{
87 return lastOutput;
88}
89
90bool CassettePort::cassetteIn(EmuTime::param time)
91{
92 // All analog filtering is ignored for now
93 // only important component is DC-removal
94 // we just assume sample has no DC component
95 int16_t sample = [&]{
96 #if COMPONENT_LASERDISC
97 if (!motorControl && laserdiscPlayer) {
98 return laserdiscPlayer->readSample(time);
99 }
100 #endif
101 return getPluggedCasDev().readSample(time); // read 1 sample
102 }();
103 return sample >= 0; // comparator
104}
105
106#if COMPONENT_LASERDISC
107void CassettePort::setLaserdiscPlayer(LaserdiscPlayer *laserdiscPlayer_)
108{
109 laserdiscPlayer = laserdiscPlayer_;
110}
111#endif
112
113std::string_view CassettePort::getDescription() const
114{
115 return "MSX Cassette port";
116}
117
118std::string_view CassettePort::getClass() const
119{
120 return "Cassette Port";
121}
122
123CassetteDevice& CassettePort::getPluggedCasDev() const
124{
125 return *checked_cast<CassetteDevice*>(&getPlugged());
126}
127
128template<typename Archive>
129void CassettePort::serialize(Archive& ar, unsigned version)
130{
131 ar.template serializeBase<Connector>(*this);
132 // don't serialize 'lastOutput', done via MSXPPI
133
134 // Must come after serialization of the connector because that one
135 // potentially serializes the CassettePlayer.
136 if (ar.versionAtLeast(version, 2)) {
137 // always serialize CassettePlayer, even if it's not plugged in.
138 ar.serializeOnlyOnce("cassettePlayer", *cassettePlayer);
139 }
140}
142
143} // 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:61
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:63
bool lastOut() const override
last bit written to CasOut.
bool cassetteIn(EmuTime::param time) override
Reads one bit from the cassette port.
DummyCassettePort(MSXMotherBoard &motherBoard)
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)