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  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  bool ready() override;
41  bool acceptsData() override;
42 
43  template<typename Archive>
44  void serialize(Archive& ar, unsigned version);
45 
46 private:
47  byte readIOImpl(word port, EmuTime::param time);
48  void writeIOImpl(word port, byte value, EmuTime::param time);
49 
50  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  bool getDSR(EmuTime::param time) override;
72  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
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::MSXRS232::writeMem
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
I8251.hh
openmsx::MSXRS232::setDataBits
void setDataBits(DataBits bits) override
Definition: MSXRS232.cc:414
openmsx::I8254
I8254
Definition: I8254.cc:546
openmsx::MSXRS232::~MSXRS232
~MSXRS232() override
openmsx::MSXRS232::writeIO
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:208
openmsx::ClockPin
Definition: ClockPin.hh:23
openmsx::MSXRS232::powerUp
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
Definition: MSXRS232.cc:60
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::IRQHelper
IntHelper< IRQSource > IRQHelper
Definition: IRQHelper.hh:135
openmsx::MSXRS232::MSXRS232
MSXRS232(const DeviceConfig &config)
Definition: MSXRS232.cc:20
openmsx::MSXRS232::readMem
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
openmsx::MSXRS232::getWriteCacheLine
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
openmsx::Ram
Ram
Definition: Ram.cc:125
openmsx::MSXRS232::recvByte
void recvByte(byte value, EmuTime::param time) override
Definition: MSXRS232.cc:429
openmsx::MSXRS232::acceptsData
bool acceptsData() override
Definition: MSXRS232.cc:409
openmsx::MSXRS232::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXRS232.cc:180
openmsx::MSXRS232::setStopBits
void setStopBits(StopBits bits) override
Definition: MSXRS232.cc:419
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::MSXRS232::getReadCacheLine
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
openmsx::MSXRS232
Definition: MSXRS232.hh:18
MSXDevice.hh
openmsx::MSXRS232::allowUnaligned
bool allowUnaligned() const override
By default we don't allow unaligned <mem> specifications in the config file.
Definition: MSXRS232.cc:140
openmsx::MSXRS232::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXRS232.cc:66
openmsx::MSXRS232::readIO
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
RS232Connector.hh
openmsx::MSXRS232::setParityBit
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXRS232.cc:424
openmsx::SerialDataInterface::StopBits
StopBits
Definition: SerialDataInterface.hh:15
openmsx::ClockPinListener
Definition: ClockPin.hh:13
openmsx::SerialDataInterface::DataBits
DataBits
Definition: SerialDataInterface.hh:12
openmsx::MSXRS232::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXRS232.cc:438
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RS232Connector
Definition: RS232Connector.hh:13
openmsx::I8251
I8251
Definition: I8251.cc:412
openmsx::SerialDataInterface::ParityBit
ParityBit
Definition: SerialDataInterface.hh:19
IRQHelper.hh
openmsx::MSXRS232::ready
bool ready() override
Definition: MSXRS232.cc:404
I8254.hh
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5