openMSX
SVIPrinterPort.cc
Go to the documentation of this file.
1 #include "SVIPrinterPort.hh"
3 #include "checked_cast.hh"
4 #include "serialize.hh"
5 #include "unreachable.hh"
6 #include <memory>
7 
8 // Centronics interface
9 //
10 // DAT0-DAT7 Printer data write port, output (10H)
11 // /STB Printer strobe port, output (11H)
12 // BUSY Printer status port, input (12H)
13 
14 namespace openmsx {
15 
17  : MSXDevice(config)
18  , Connector(MSXDevice::getPluggingController(), "printerport",
19  std::make_unique<DummyPrinterPortDevice>())
20 {
21  data = 255; // != 0;
22  strobe = false; // != true;
24 }
25 
26 void SVIPrinterPort::reset(EmuTime::param time)
27 {
28  writeData(0, time); // TODO check this
29  setStrobe(true, time); // TODO check this
30 }
31 
32 byte SVIPrinterPort::readIO(word port, EmuTime::param time)
33 {
34  return peekIO(port, time);
35 }
36 
37 byte SVIPrinterPort::peekIO(word /*port*/, EmuTime::param time) const
38 {
39  // bit 1 = status / other bits always 1
40  return getPluggedPrintDev().getStatus(time) ? 0xFF : 0xFE;
41 }
42 
43 void SVIPrinterPort::writeIO(word port, byte value, EmuTime::param time)
44 {
45  switch (port & 0x01) {
46  case 0:
47  writeData(value, time);
48  break;
49  case 1:
50  setStrobe(value & 1, time); // bit 0 = strobe
51  break;
52  default:
54  }
55 }
56 
57 void SVIPrinterPort::setStrobe(bool newStrobe, EmuTime::param time)
58 {
59  if (newStrobe != strobe) {
60  strobe = newStrobe;
61  getPluggedPrintDev().setStrobe(strobe, time);
62  }
63 }
64 void SVIPrinterPort::writeData(byte newData, EmuTime::param time)
65 {
66  if (newData != data) {
67  data = newData;
68  getPluggedPrintDev().writeData(data, time);
69  }
70 }
71 
72 std::string_view SVIPrinterPort::getDescription() const
73 {
74  return "Spectravideo SVI-328 Printer port";
75 }
76 
77 std::string_view SVIPrinterPort::getClass() const
78 {
79  return "Printer Port";
80 }
81 
82 void SVIPrinterPort::plug(Pluggable& dev, EmuTime::param time)
83 {
84  Connector::plug(dev, time);
85  getPluggedPrintDev().writeData(data, time);
86  getPluggedPrintDev().setStrobe(strobe, time);
87 }
88 
90 {
91  return *checked_cast<PrinterPortDevice*>(&getPlugged());
92 }
93 
94 template<typename Archive>
95 void SVIPrinterPort::serialize(Archive& ar, unsigned /*version*/)
96 {
97  ar.template serializeBase<MSXDevice>(*this);
98  ar.template serializeBase<Connector>(*this);
99  ar.serialize("strobe", strobe,
100  "data", data);
101  // TODO force writing data to port??
102 }
104 REGISTER_MSXDEVICE(SVIPrinterPort, "SVI-328 PrinterPort");
105 
106 } // 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:32
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:132
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.
void serialize(Archive &ar, unsigned version)
void plug(Pluggable &dev, EmuTime::param time) override
This plugs a Pluggable in this Connector.
std::string_view getClass() const override
A Connector belong to a certain class.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
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.
SVIPrinterPort(const DeviceConfig &config)
std::string_view getDescription() const override
Get a description for this connector.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void reset(EmuTime::param time) override
This method is called on reset.
PrinterPortDevice & getPluggedPrintDev() const
This file implemented 3 utility functions:
Definition: Autofire.cc:5
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983
#define UNREACHABLE
Definition: unreachable.hh:38