openMSX
MSXPrinterPort.cc
Go to the documentation of this file.
1#include "MSXPrinterPort.hh"
3#include "checked_cast.hh"
4#include "narrow.hh"
5#include "outer.hh"
6#include "serialize.hh"
7#include "unreachable.hh"
8#include <cstdint>
9#include <memory>
10
11namespace openmsx {
12
14 : MSXDevice(config)
15 , Connector(MSXDevice::getPluggingController(), "printerport",
16 std::make_unique<DummyPrinterPortDevice>())
17 , debuggable(getMotherBoard(), MSXDevice::getName())
18{
20}
21
22void MSXPrinterPort::reset(EmuTime::param time)
23{
24 writeData(0, time); // TODO check this
25 setStrobe(true, time); // TODO check this
26}
27
28uint8_t MSXPrinterPort::readIO(uint16_t port, EmuTime::param time)
29{
30 return peekIO(port, time);
31}
32
33uint8_t MSXPrinterPort::peekIO(uint16_t /*port*/, EmuTime::param time) const
34{
35 // bit 1 = status / other bits always 1
36 return getPluggedPrintDev().getStatus(time)
37 ? 0xFF : 0xFD;
38}
39
40void MSXPrinterPort::writeIO(uint16_t port, uint8_t value, EmuTime::param time)
41{
42 switch (port & 0x01) {
43 case 0:
44 setStrobe(value & 1, time); // bit 0 = strobe
45 break;
46 case 1:
47 writeData(value, time);
48 break;
49 default:
51 }
52}
53
54void MSXPrinterPort::setStrobe(bool newStrobe, EmuTime::param time)
55{
56 if (newStrobe != strobe) {
57 strobe = newStrobe;
58 getPluggedPrintDev().setStrobe(strobe, time);
59 }
60}
61void MSXPrinterPort::writeData(uint8_t newData, EmuTime::param time)
62{
63 if (newData != data) {
64 data = newData;
65 getPluggedPrintDev().writeData(data, time);
66 }
67}
68
69std::string_view MSXPrinterPort::getDescription() const
70{
71 return "MSX Printer port";
72}
73
74std::string_view MSXPrinterPort::getClass() const
75{
76 return "Printer Port";
77}
78
79void MSXPrinterPort::plug(Pluggable& dev, EmuTime::param time)
80{
81 Connector::plug(dev, time);
82 getPluggedPrintDev().writeData(data, time);
83 getPluggedPrintDev().setStrobe(strobe, time);
84}
85
86PrinterPortDevice& MSXPrinterPort::getPluggedPrintDev() const
87{
88 return *checked_cast<PrinterPortDevice*>(&getPlugged());
89}
90
91
92MSXPrinterPort::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
93 : SimpleDebuggable(motherBoard_, name_, "Printer Port", 2)
94{
95}
96
97uint8_t MSXPrinterPort::Debuggable::read(unsigned address)
98{
99 auto& pPort = OUTER(MSXPrinterPort, debuggable);
100 return (address == 0) ? pPort.strobe : pPort.data;
101}
102
103void MSXPrinterPort::Debuggable::write(unsigned address, uint8_t value)
104{
105 auto& pPort = OUTER(MSXPrinterPort, debuggable);
106 pPort.writeIO(narrow<uint16_t>(address), value, pPort.getCurrentTime());
107}
108
109
110template<typename Archive>
111void MSXPrinterPort::serialize(Archive& ar, unsigned /*version*/)
112{
113 ar.template serializeBase<MSXDevice>(*this);
114 ar.template serializeBase<Connector>(*this);
115 ar.serialize("strobe", strobe,
116 "data", data);
117 // TODO force writing data to port??
118}
121
122} // 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:36
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.
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