OXYGENHUB
◆ main openmsx / src / PrinterPortSimpl.cc
1.7 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "PrinterPortSimpl.hh"
2
3
#include "DeviceConfig.hh"
4
#include "XMLElement.hh"
5
#include "serialize.hh"
6
7
namespace openmsx {
8
9
static constexpr zstring_view DESCRIPTION =
10
	"Play samples via your printer port.";
11
12
PrinterPortSimpl::PrinterPortSimpl(HardwareConfig& hwConf_)
13
	: hwConf(hwConf_)
14
{
15
}
16
17
bool PrinterPortSimpl::getStatus(EmuTime /*time*/)
18
{
19
	return true; // TODO check
20
}
21
22
void PrinterPortSimpl::setStrobe(bool /*strobe*/, EmuTime /*time*/)
23
{
24
	// ignore strobe // TODO check
25
}
26
27
void PrinterPortSimpl::writeData(uint8_t data, EmuTime time)
28
{
29
	assert(dac);
30
	dac->writeDAC(data, time);
31
}
32
33
void PrinterPortSimpl::createDAC()
34
{
35
	static XMLElement* xml = [] {
36
		auto& doc = XMLDocument::getStaticDocument();
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",
43
	            static_string_view{static_string_view::lifetime_ok_tag{}, DESCRIPTION},
44
	            DeviceConfig(hwConf, *xml));
45
}
46
47
void PrinterPortSimpl::plugHelper(Connector& /*connector*/, EmuTime /*time*/)
48
{
49
	createDAC();
50
}
51
52
void PrinterPortSimpl::unplugHelper(EmuTime /*time*/)
53
{
54
	dac.reset();
55
}
56
57
zstring_view PrinterPortSimpl::getName() const
58
{
59
	return "simpl";
60
}
61
62
zstring_view PrinterPortSimpl::getDescription() const
63
{
64
	return DESCRIPTION;
65
}
66
67
template<typename Archive>
68
void PrinterPortSimpl::serialize(Archive& ar, unsigned /*version*/)
69
{
70
	if (isPluggedIn()) {
71
		if constexpr (Archive::IS_LOADER) {
72
			createDAC();
73
		}
74
		ar.serialize("dac", *dac);
75
	}
76
}
77
INSTANTIATE_SERIALIZE_METHODS(PrinterPortSimpl);
78
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, PrinterPortSimpl, "PrinterPortSimpl");
79
80
} // namespace openmsx