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 
9 namespace openmsx {
10 
12  : MSXDevice(config)
13  , Connector(MSXDevice::getPluggingController(), "printerport",
14  std::make_unique<DummyPrinterPortDevice>())
15  , debuggable(getMotherBoard(), MSXDevice::getName())
16  , strobe(false) // != true
17  , data(255) // != 0
18 {
20 }
21 
22 void MSXPrinterPort::reset(EmuTime::param time)
23 {
24  writeData(0, time); // TODO check this
25  setStrobe(true, time); // TODO check this
26 }
27 
28 byte MSXPrinterPort::readIO(word port, EmuTime::param time)
29 {
30  return peekIO(port, time);
31 }
32 
33 byte MSXPrinterPort::peekIO(word /*port*/, EmuTime::param time) const
34 {
35  // bit 1 = status / other bits always 1
36  return getPluggedPrintDev().getStatus(time)
37  ? 0xFF : 0xFD;
38 }
39 
40 void MSXPrinterPort::writeIO(word port, byte 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 
54 void MSXPrinterPort::setStrobe(bool newStrobe, EmuTime::param time)
55 {
56  if (newStrobe != strobe) {
57  strobe = newStrobe;
58  getPluggedPrintDev().setStrobe(strobe, time);
59  }
60 }
61 void MSXPrinterPort::writeData(byte newData, EmuTime::param time)
62 {
63  if (newData != data) {
64  data = newData;
65  getPluggedPrintDev().writeData(data, time);
66  }
67 }
68 
69 std::string_view MSXPrinterPort::getDescription() const
70 {
71  return "MSX Printer port";
72 }
73 
74 std::string_view MSXPrinterPort::getClass() const
75 {
76  return "Printer Port";
77 }
78 
79 void 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 
87 {
88  return *checked_cast<PrinterPortDevice*>(&getPlugged());
89 }
90 
91 
92 MSXPrinterPort::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
93  : SimpleDebuggable(motherBoard_, name_, "Printer Port", 2)
94 {
95 }
96 
97 byte MSXPrinterPort::Debuggable::read(unsigned address)
98 {
99  auto& pPort = OUTER(MSXPrinterPort, debuggable);
100  return (address == 0) ? pPort.strobe : pPort.data;
101 }
102 
103 void MSXPrinterPort::Debuggable::write(unsigned address, byte value)
104 {
105  auto& pPort = OUTER(MSXPrinterPort, debuggable);
106  pPort.writeIO(address, value, pPort.getCurrentTime());
107 }
108 
109 
110 template<typename Archive>
111 void 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:33
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:126
void serialize(Archive &ar, unsigned version)
std::string_view getDescription() const override
Get a description for this connector.
MSXPrinterPort(const DeviceConfig &config)
void reset(EmuTime::param time) override
This method is called on reset.
PrinterPortDevice & getPluggedPrintDev() const
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void writeIO(word port, byte 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(byte 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:727
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define OUTER(type, member)
Definition: outer.hh:41
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1009
#define UNREACHABLE
Definition: unreachable.hh:38