openMSX
MSXRS232.hh
Go to the documentation of this file.
1#ifndef MSXRS232_HH
2#define MSXRS232_HH
3
4#include "I8251.hh"
5#include "I8254.hh"
6#include "IRQHelper.hh"
7#include "MSXDevice.hh"
8#include "RS232Connector.hh"
9
10#include <memory>
11
12namespace openmsx {
13
14class Ram;
15class Rom;
16class BooleanSetting;
17
18class MSXRS232 final : public MSXDevice, public RS232Connector
19{
20public:
21 explicit MSXRS232(const DeviceConfig& config);
22 ~MSXRS232() override;
23
24 void powerUp(EmuTime::param time) override;
25 void reset(EmuTime::param time) override;
26 [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
27 [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
28 void writeIO(word port, byte value, EmuTime::param time) override;
29 [[nodiscard]] byte readMem(word address, EmuTime::param time) override;
30 // TODO: implement peekMem, because the default isn't OK anymore
31 [[nodiscard]] const byte *getReadCacheLine(word start) const override;
32 void writeMem(word address, byte value, EmuTime::param time) override;
33 [[nodiscard]] byte* getWriteCacheLine(word start) override;
34 [[nodiscard]] bool allowUnaligned() const override;
35
36 // RS232Connector (input)
37 void setDataBits(DataBits bits) override;
38 void setStopBits(StopBits bits) override;
39 void setParityBit(bool enable, Parity parity) override;
40 void recvByte(byte value, EmuTime::param time) override;
41 [[nodiscard]] bool ready() override;
42 [[nodiscard]] bool acceptsData() override;
43
44 template<typename Archive>
45 void serialize(Archive& ar, unsigned version);
46
47private:
48 [[nodiscard]] byte readIOImpl(word port, EmuTime::param time);
49 void writeIOImpl(word port, byte value, EmuTime::param time);
50
51 [[nodiscard]] byte readStatus(EmuTime::param time);
52 void setIRQMask(byte value);
53 void setRxRDYIRQ(bool status);
54 void enableRxRDYIRQ(bool enabled);
55
56 struct Counter0 final : ClockPinListener {
57 void signal(ClockPin& pin, EmuTime::param time) override;
58 void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
59 } cntr0; // counter 0 rx clock pin
60
61 struct Counter1 final : ClockPinListener {
62 void signal(ClockPin& pin, EmuTime::param time) override;
63 void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
64 } cntr1; // counter 1 tx clock pin
65
66 I8254 i8254;
67
68 struct Interface final : I8251Interface {
69 void setRxRDY(bool status, EmuTime::param time) override;
70 void setDTR(bool status, EmuTime::param time) override;
71 void setRTS(bool status, EmuTime::param time) override;
72 [[nodiscard]] bool getDSR(EmuTime::param time) override;
73 [[nodiscard]] bool getCTS(EmuTime::param time) override;
74 void setDataBits(DataBits bits) override;
75 void setStopBits(StopBits bits) override;
76 void setParityBit(bool enable, Parity parity) override;
77 void recvByte(byte value, EmuTime::param time) override;
78 void signal(EmuTime::param time) override;
79 } interface;
80
81 I8251 i8251;
82 const std::unique_ptr<Rom> rom; // can be nullptr
83 const std::unique_ptr<Ram> ram; // can be nullptr
84
85 IRQHelper rxrdyIRQ;
86 bool rxrdyIRQlatch = false;
87 bool rxrdyIRQenabled = false;
88
89 const bool hasMemoryBasedIo;
90 const bool hasRIPin;
91 const bool inputsPullup;
92 bool ioAccessEnabled;
93
94 const std::unique_ptr<BooleanSetting> switchSetting; // can be nullptr
95};
97
98
99} // namespace openmsx
100
101#endif
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
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 MSXRS232.cc:199
void setDataBits(DataBits bits) override
Definition MSXRS232.cc:402
void reset(EmuTime::param time) override
This method is called on reset.
Definition MSXRS232.cc:69
bool acceptsData() override
Definition MSXRS232.cc:397
bool ready() override
Definition MSXRS232.cc:392
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition MSXRS232.cc:149
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition MSXRS232.cc:63
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition MSXRS232.cc:95
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
Definition MSXRS232.cc:110
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition MSXRS232.cc:80
byte * getWriteCacheLine(word start) override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition MSXRS232.cc:130
void setStopBits(StopBits bits) override
Definition MSXRS232.cc:407
bool allowUnaligned() const override
By default we don't allow unaligned <mem> specifications in the config file.
Definition MSXRS232.cc:143
void serialize(Archive &ar, unsigned version)
Definition MSXRS232.cc:426
void setParityBit(bool enable, Parity parity) override
Definition MSXRS232.cc:412
void recvByte(byte value, EmuTime::param time) override
Definition MSXRS232.cc:417
~MSXRS232() override
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition MSXRS232.cc:177
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
IntHelper< IRQSource > IRQHelper
Definition IRQHelper.hh:124
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)