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
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:31
serialize.hh
openmsx::PrinterPortDevice::setStrobe
virtual void setStrobe(bool strobe, EmuTime::param time)=0
Sets the strobe signal: false = low, true = high.
openmsx::DummyPrinterPortDevice
Definition: DummyPrinterPortDevice.hh:8
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
DummyPrinterPortDevice.hh
openmsx::SVIPrinterPort::getClass
std::string_view getClass() const override
A Connector belong to a certain class.
Definition: SVIPrinterPort.cc:77
openmsx::SVIPrinterPort::serialize
void serialize(Archive &ar, unsigned version)
Definition: SVIPrinterPort.cc:95
SVIPrinterPort.hh
openmsx::SVIPrinterPort::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: SVIPrinterPort.cc:37
openmsx::Pluggable
Definition: Pluggable.hh:11
openmsx::SVIPrinterPort::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: SVIPrinterPort.cc:26
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
UNREACHABLE
#define UNREACHABLE
Definition: unreachable.hh:38
openmsx::SVIPrinterPort::getDescription
std::string_view getDescription() const override
Get a description for this connector.
Definition: SVIPrinterPort.cc:72
openmsx::PrinterPortDevice::getStatus
virtual bool getStatus(EmuTime::param time)=0
Returns the STATUS signal: false = low = ready, true = high = not ready.
openmsx::MSXDevice::getCurrentTime
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:131
openmsx::SVIPrinterPort::writeIO
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.
Definition: SVIPrinterPort.cc:43
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::Connector::plug
virtual void plug(Pluggable &device, EmuTime::param time)
This plugs a Pluggable in this Connector.
Definition: Connector.cc:25
openmsx::SVIPrinterPort::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: SVIPrinterPort.cc:32
openmsx::SVIPrinterPort
Definition: SVIPrinterPort.hh:11
checked_cast.hh
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::SVIPrinterPort::plug
void plug(Pluggable &dev, EmuTime::param time) override
This plugs a Pluggable in this Connector.
Definition: SVIPrinterPort.cc:82
openmsx::Connector
Represents something you can plug devices into.
Definition: Connector.hh:20
unreachable.hh
openmsx::SVIPrinterPort::getPluggedPrintDev
PrinterPortDevice & getPluggedPrintDev() const
Definition: SVIPrinterPort.cc:89
openmsx::PrinterPortDevice
Definition: PrinterPortDevice.hh:9
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::PrinterPortDevice::writeData
virtual void writeData(byte data, EmuTime::param time)=0
Sets the data signals.
openmsx::Connector::getPlugged
Pluggable & getPlugged() const
Returns the Pluggable currently plugged in.
Definition: Connector.hh:59
openmsx::SVIPrinterPort::SVIPrinterPort
SVIPrinterPort(const DeviceConfig &config)
Definition: SVIPrinterPort.cc:16