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  byte readIO(word port, EmuTime::param time) override;
26  byte peekIO(word port, EmuTime::param time) const override;
27  void writeIO(word port, byte value, EmuTime::param time) override;
28  byte readMem(word address, EmuTime::param time) override;
29  // TODO: implement peekMem, because the default isn't OK anymore
30  const byte *getReadCacheLine(word start) const override;
31  void writeMem(word address, byte value, EmuTime::param time) override;
32  byte* getWriteCacheLine(word start) const override;
33 
34  // RS232Connector (input)
35  void setDataBits(DataBits bits) override;
36  void setStopBits(StopBits bits) override;
37  void setParityBit(bool enable, ParityBit parity) override;
38  void recvByte(byte value, EmuTime::param time) override;
39  bool ready() override;
40  bool acceptsData() override;
41 
42  template<typename Archive>
43  void serialize(Archive& ar, unsigned version);
44 
45 private:
46  byte readIOImpl(word port, EmuTime::param time);
47  void writeIOImpl(word port, byte value, EmuTime::param time);
48 
49  byte readStatus(EmuTime::param time);
50  void setIRQMask(byte value);
51  void setRxRDYIRQ(bool status);
52  void enableRxRDYIRQ(bool enabled);
53 
54  struct Counter0 final : ClockPinListener {
55  void signal(ClockPin& pin, EmuTime::param time) override;
56  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
57  } cntr0; // counter 0 rx clock pin
58 
59  struct Counter1 final : ClockPinListener {
60  void signal(ClockPin& pin, EmuTime::param time) override;
61  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
62  } cntr1; // counter 1 tx clock pin
63 
64  I8254 i8254;
65 
66  struct I8251Interf final : I8251Interface {
67  void setRxRDY(bool status, EmuTime::param time) override;
68  void setDTR(bool status, EmuTime::param time) override;
69  void setRTS(bool status, EmuTime::param time) override;
70  bool getDSR(EmuTime::param time) override;
71  bool getCTS(EmuTime::param time) override;
72  void setDataBits(DataBits bits) override;
73  void setStopBits(StopBits bits) override;
74  void setParityBit(bool enable, ParityBit parity) override;
75  void recvByte(byte value, EmuTime::param time) override;
76  void signal(EmuTime::param time) override;
77  } interf;
78 
79  I8251 i8251;
80  const std::unique_ptr<Rom> rom; // can be nullptr
81  const std::unique_ptr<Ram> ram; // can be nullptr
82 
83  IRQHelper rxrdyIRQ;
84  bool rxrdyIRQlatch;
85  bool rxrdyIRQenabled;
86 
87  const bool hasMemoryBasedIo;
88  bool ioAccessEnabled;
89 
90  const std::unique_ptr<BooleanSetting> switchSetting; // can be nullptr
91 };
93 
94 
95 } // namespace openmsx
96 
97 #endif
MSXRS232(const DeviceConfig &config)
Definition: MSXRS232.cc:19
void serialize(Archive &ar, unsigned version)
Definition: MSXRS232.cc:431
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: MSXRS232.cc:76
bool acceptsData() override
Definition: MSXRS232.cc:402
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:139
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXRS232.cc:417
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXRS232.cc:173
Ram
Definition: Ram.cc:124
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
bool ready() override
Definition: MSXRS232.cc:397
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXRS232.cc:65
void setDataBits(DataBits bits) override
Definition: MSXRS232.cc:407
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
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:106
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing...
Definition: MSXRS232.cc:126
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:201
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:91
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition: MSXRS232.cc:59
void setStopBits(StopBits bits) override
Definition: MSXRS232.cc:412
void recvByte(byte value, EmuTime::param time) override
Definition: MSXRS232.cc:422
~MSXRS232() override