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
14namespace openmsx {
15
17 : MSXDevice(config)
18 , Connector(MSXDevice::getPluggingController(), "printerport",
19 std::make_unique<DummyPrinterPortDevice>())
20 , strobe(false) // != true
21 , data(255) // != 0
22{
24}
25
26void SVIPrinterPort::reset(EmuTime::param time)
27{
28 writeData(0, time); // TODO check this
29 setStrobe(true, time); // TODO check this
30}
31
32byte SVIPrinterPort::readIO(word port, EmuTime::param time)
33{
34 return peekIO(port, time);
35}
36
37byte 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
43void 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
57void SVIPrinterPort::setStrobe(bool newStrobe, EmuTime::param time)
58{
59 if (newStrobe != strobe) {
60 strobe = newStrobe;
61 getPluggedPrintDev().setStrobe(strobe, time);
62 }
63}
64void SVIPrinterPort::writeData(byte newData, EmuTime::param time)
65{
66 if (newData != data) {
67 data = newData;
68 getPluggedPrintDev().writeData(data, time);
69 }
70}
71
72std::string_view SVIPrinterPort::getDescription() const
73{
74 return "Spectravideo SVI-328 Printer port";
75}
76
77std::string_view SVIPrinterPort::getClass() const
78{
79 return "Printer Port";
80}
81
82void 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
94template<typename Archive>
95void 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}
104REGISTER_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:33
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:126
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:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1009
#define UNREACHABLE
Definition: unreachable.hh:38