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