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 assert(dac);
30 dac->writeDAC(data, time);
31}
32
33void PrinterPortSimpl::createDAC()
34{
35 static const XMLElement* xml = [] {
37 auto* result = doc.allocateElement("simpl");
38 result->setFirstChild(doc.allocateElement("sound"))
39 ->setFirstChild(doc.allocateElement("volume", "12000"));
40 return result;
41 }();
42 dac.emplace("simpl", DESCRIPTION, DeviceConfig(hwConf, *xml));
43}
44
45void PrinterPortSimpl::plugHelper(Connector& /*connector*/, EmuTime::param /*time*/)
46{
47 createDAC();
48}
49
50void PrinterPortSimpl::unplugHelper(EmuTime::param /*time*/)
51{
52 dac.reset();
53}
54
55std::string_view PrinterPortSimpl::getName() const
56{
57 return "simpl";
58}
59
60std::string_view PrinterPortSimpl::getDescription() const
61{
62 return DESCRIPTION;
63}
64
65template<typename Archive>
66void PrinterPortSimpl::serialize(Archive& ar, unsigned /*version*/)
67{
68 if (isPluggedIn()) {
69 if constexpr (Archive::IS_LOADER) {
70 createDAC();
71 }
72 ar.serialize("dac", *dac);
73 }
74}
77
78} // 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()
static_string_view
This file implemented 3 utility functions:
Definition Autofire.cc:11
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define REGISTER_POLYMORPHIC_INITIALIZER(BASE, CLASS, NAME)