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