openMSX
PrinterPortSimpl.cc
Go to the documentation of this file.
1#include "PrinterPortSimpl.hh"
2#include "DeviceConfig.hh"
3#include "XMLElement.hh"
4#include "serialize.hh"
5#include <memory>
6
7namespace openmsx {
8
9static constexpr static_string_view DESCRIPTION =
10 "Play samples via your printer port.";
11
13 : hwConf(hwConf_)
14{
15}
16
17bool PrinterPortSimpl::getStatus(EmuTime::param /*time*/)
18{
19 return true; // TODO check
20}
21
22void PrinterPortSimpl::setStrobe(bool /*strobe*/, EmuTime::param /*time*/)
23{
24 // ignore strobe // TODO check
25}
26
27void PrinterPortSimpl::writeData(uint8_t data, EmuTime::param time)
28{
29 dac->writeDAC(data, time);
30}
31
32void PrinterPortSimpl::createDAC()
33{
34 static const XMLElement* xml = [] {
36 auto* result = doc.allocateElement("simpl");
37 result->setFirstChild(doc.allocateElement("sound"))
38 ->setFirstChild(doc.allocateElement("volume", "12000"));
39 return result;
40 }();
41 dac.emplace("simpl", DESCRIPTION, DeviceConfig(hwConf, *xml));
42}
43
44void PrinterPortSimpl::plugHelper(Connector& /*connector*/, EmuTime::param /*time*/)
45{
46 createDAC();
47}
48
49void PrinterPortSimpl::unplugHelper(EmuTime::param /*time*/)
50{
51 dac.reset();
52}
53
54std::string_view PrinterPortSimpl::getName() const
55{
56 return "simpl";
57}
58
59std::string_view PrinterPortSimpl::getDescription() const
60{
61 return DESCRIPTION;
62}
63
64template<typename Archive>
65void PrinterPortSimpl::serialize(Archive& ar, unsigned /*version*/)
66{
67 if (isPluggedIn()) {
68 if constexpr (Archive::IS_LOADER) {
69 createDAC();
70 }
71 ar.serialize("dac", *dac);
72 }
73}
76
77} // namespace openmsx
Represents something you can plug devices into.
Definition: Connector.hh:21
bool isPluggedIn() const
Returns true if this pluggable is currently plugged into a connector.
Definition: Pluggable.hh:49
PrinterPortSimpl(const HardwareConfig &hwConf)
void unplugHelper(EmuTime::param time) override
bool getStatus(EmuTime::param time) override
Returns the STATUS signal: false = low = ready, true = high = not ready.
void serialize(Archive &ar, unsigned version)
void plugHelper(Connector &connector, EmuTime::param time) override
std::string_view getDescription() const override
Description for this pluggable.
void setStrobe(bool strobe, EmuTime::param time) override
Sets the strobe signal: false = low, true = high.
void writeData(uint8_t data, EmuTime::param time) override
Sets the data signals.
std::string_view getName() const override
Name used to identify this pluggable.
static XMLDocument & getStaticDocument()
Definition: XMLElement.hh:255
static_string_view
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021