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{
22}
23
24void SVIPrinterPort::reset(EmuTime::param time)
25{
26 writeData(0, time); // TODO check this
27 setStrobe(true, time); // TODO check this
28}
29
30uint8_t SVIPrinterPort::readIO(uint16_t port, EmuTime::param time)
31{
32 return peekIO(port, time);
33}
34
35uint8_t SVIPrinterPort::peekIO(uint16_t /*port*/, EmuTime::param time) const
36{
37 // bit 1 = status / other bits always 1
38 return getPluggedPrintDev().getStatus(time) ? 0xFF : 0xFE;
39}
40
41void SVIPrinterPort::writeIO(uint16_t port, uint8_t value, EmuTime::param time)
42{
43 switch (port & 0x01) {
44 case 0:
45 writeData(value, time);
46 break;
47 case 1:
48 setStrobe(value & 1, time); // bit 0 = strobe
49 break;
50 default:
52 }
53}
54
55void SVIPrinterPort::setStrobe(bool newStrobe, EmuTime::param time)
56{
57 if (newStrobe != strobe) {
58 strobe = newStrobe;
59 getPluggedPrintDev().setStrobe(strobe, time);
60 }
61}
62void SVIPrinterPort::writeData(uint8_t newData, EmuTime::param time)
63{
64 if (newData != data) {
65 data = newData;
66 getPluggedPrintDev().writeData(data, time);
67 }
68}
69
70std::string_view SVIPrinterPort::getDescription() const
71{
72 return "Spectravideo SVI-328 Printer port";
73}
74
75std::string_view SVIPrinterPort::getClass() const
76{
77 return "Printer Port";
78}
79
80void SVIPrinterPort::plug(Pluggable& dev, EmuTime::param time)
81{
82 Connector::plug(dev, time);
83 getPluggedPrintDev().writeData(data, time);
84 getPluggedPrintDev().setStrobe(strobe, time);
85}
86
88{
89 return *checked_cast<PrinterPortDevice*>(&getPlugged());
90}
91
92template<typename Archive>
93void SVIPrinterPort::serialize(Archive& ar, unsigned /*version*/)
94{
95 ar.template serializeBase<MSXDevice>(*this);
96 ar.template serializeBase<Connector>(*this);
97 ar.serialize("strobe", strobe,
98 "data", data);
99 // TODO force writing data to port??
100}
102REGISTER_MSXDEVICE(SVIPrinterPort, "SVI-328 PrinterPort");
103
104} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
Represents something you can plug devices into.
Definition Connector.hh:21
Pluggable & getPlugged() const
Returns the Pluggable currently plugged in.
Definition Connector.hh:61
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:36
EmuTime::param getCurrentTime() const
Definition MSXDevice.cc:125
virtual bool getStatus(EmuTime::param time)=0
Returns the STATUS signal: false = low = ready, true = high = not ready.
virtual void writeData(uint8_t 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.
void writeIO(uint16_t port, uint8_t value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
SVIPrinterPort(const DeviceConfig &config)
uint8_t peekIO(uint16_t port, EmuTime::param time) const override
Read a byte from a given IO port.
std::string_view getDescription() const override
Get a description for this connector.
uint8_t readIO(uint16_t port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void reset(EmuTime::param time) override
This method is called on reset.
PrinterPortDevice & getPluggedPrintDev() const
This file implemented 3 utility functions:
Definition Autofire.cc:11
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define UNREACHABLE