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 
7 namespace openmsx {
8 
10  "Play samples via your printer port.";
11 
13  : hwConf(hwConf_)
14 {
15 }
16 
17 bool PrinterPortSimpl::getStatus(EmuTime::param /*time*/)
18 {
19  return true; // TODO check
20 }
21 
22 void PrinterPortSimpl::setStrobe(bool /*strobe*/, EmuTime::param /*time*/)
23 {
24  // ignore strobe // TODO check
25 }
26 
27 void PrinterPortSimpl::writeData(byte data, EmuTime::param time)
28 {
29  dac->writeDAC(data, time);
30 }
31 
32 void PrinterPortSimpl::createDAC()
33 {
34  static XMLElement* xml = [] {
35  auto& doc = XMLDocument::getStaticDocument();
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 
44 void PrinterPortSimpl::plugHelper(Connector& /*connector*/, EmuTime::param /*time*/)
45 {
46  createDAC();
47 }
48 
49 void PrinterPortSimpl::unplugHelper(EmuTime::param /*time*/)
50 {
51  dac.reset();
52 }
53 
54 std::string_view PrinterPortSimpl::getName() const
55 {
56  return "simpl";
57 }
58 
59 std::string_view PrinterPortSimpl::getDescription() const
60 {
61  return DESCRIPTION;
62 }
63 
64 template<typename Archive>
65 void 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(byte 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:258
static_string_view
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
constexpr static_string_view DESCRIPTION
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:998