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