openMSX
MSXPrinterPort.cc
Go to the documentation of this file.
1#include "MSXPrinterPort.hh"
3#include "checked_cast.hh"
4#include "outer.hh"
5#include "serialize.hh"
6#include "unreachable.hh"
7#include <memory>
8
9namespace openmsx {
10
12 : MSXDevice(config)
13 , Connector(MSXDevice::getPluggingController(), "printerport",
14 std::make_unique<DummyPrinterPortDevice>())
15 , debuggable(getMotherBoard(), MSXDevice::getName())
16{
18}
19
20void MSXPrinterPort::reset(EmuTime::param time)
21{
22 writeData(0, time); // TODO check this
23 setStrobe(true, time); // TODO check this
24}
25
26uint8_t MSXPrinterPort::readIO(uint16_t port, EmuTime::param time)
27{
28 return peekIO(port, time);
29}
30
31uint8_t MSXPrinterPort::peekIO(uint16_t /*port*/, EmuTime::param time) const
32{
33 // bit 1 = status / other bits always 1
34 return getPluggedPrintDev().getStatus(time)
35 ? 0xFF : 0xFD;
36}
37
38void MSXPrinterPort::writeIO(uint16_t port, uint8_t value, EmuTime::param time)
39{
40 switch (port & 0x01) {
41 case 0:
42 setStrobe(value & 1, time); // bit 0 = strobe
43 break;
44 case 1:
45 writeData(value, time);
46 break;
47 default:
49 }
50}
51
52void MSXPrinterPort::setStrobe(bool newStrobe, EmuTime::param time)
53{
54 if (newStrobe != strobe) {
55 strobe = newStrobe;
56 getPluggedPrintDev().setStrobe(strobe, time);
57 }
58}
59void MSXPrinterPort::writeData(uint8_t newData, EmuTime::param time)
60{
61 if (newData != data) {
62 data = newData;
63 getPluggedPrintDev().writeData(data, time);
64 }
65}
66
67std::string_view MSXPrinterPort::getDescription() const
68{
69 return "MSX Printer port";
70}
71
72std::string_view MSXPrinterPort::getClass() const
73{
74 return "Printer Port";
75}
76
77void MSXPrinterPort::plug(Pluggable& dev, EmuTime::param time)
78{
79 Connector::plug(dev, time);
80 getPluggedPrintDev().writeData(data, time);
81 getPluggedPrintDev().setStrobe(strobe, time);
82}
83
85{
86 return *checked_cast<PrinterPortDevice*>(&getPlugged());
87}
88
89
90MSXPrinterPort::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
91 : SimpleDebuggable(motherBoard_, name_, "Printer Port", 2)
92{
93}
94
95uint8_t MSXPrinterPort::Debuggable::read(unsigned address)
96{
97 auto& pPort = OUTER(MSXPrinterPort, debuggable);
98 return (address == 0) ? pPort.strobe : pPort.data;
99}
100
101void MSXPrinterPort::Debuggable::write(unsigned address, uint8_t value)
102{
103 auto& pPort = OUTER(MSXPrinterPort, debuggable);
104 pPort.writeIO(address, value, pPort.getCurrentTime());
105}
106
107
108template<typename Archive>
109void MSXPrinterPort::serialize(Archive& ar, unsigned /*version*/)
110{
111 ar.template serializeBase<MSXDevice>(*this);
112 ar.template serializeBase<Connector>(*this);
113 ar.serialize("strobe", strobe,
114 "data", data);
115 // TODO force writing data to port??
116}
119
120} // namespace openmsx
Represents something you can plug devices into.
Definition: Connector.hh:21
Pluggable & getPlugged() const
Returns the Pluggable currently plugged in.
Definition: Connector.hh:59
virtual void plug(Pluggable &device, EmuTime::param time)
This plugs a Pluggable in this Connector.
Definition: Connector.cc:25
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:34
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:125
void serialize(Archive &ar, unsigned version)
std::string_view getDescription() const override
Get a description for this connector.
uint8_t readIO(uint16_t port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
MSXPrinterPort(const DeviceConfig &config)
void reset(EmuTime::param time) override
This method is called on reset.
PrinterPortDevice & getPluggedPrintDev() const
uint8_t peekIO(uint16_t port, EmuTime::param time) const override
Read a byte from a given IO port.
void writeIO(uint16_t port, uint8_t value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
std::string_view getClass() const override
A Connector belong to a certain class.
void plug(Pluggable &dev, EmuTime::param time) override
This plugs a Pluggable in this Connector.
virtual bool getStatus(EmuTime::param time)=0
Returns the STATUS signal: false = low = ready, true = high = not ready.
virtual void writeData(uint8_t data, EmuTime::param time)=0
Sets the data signals.
virtual void setStrobe(bool strobe, EmuTime::param time)=0
Sets the strobe signal: false = low, true = high.
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
STL namespace.
#define OUTER(type, member)
Definition: outer.hh:41
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021
#define UNREACHABLE
Definition: unreachable.hh:38