openMSX
I8251.hh
Go to the documentation of this file.
1 // This class implements the Intel 8251 chip (UART)
2 
3 #ifndef I8251_HH
4 #define I8251_HH
5 
6 #include "ClockPin.hh"
7 #include "SerialDataInterface.hh"
8 #include "Schedulable.hh"
9 #include "serialize_meta.hh"
10 #include "openmsx.hh"
11 #include "outer.hh"
12 
13 namespace openmsx {
14 
16 {
17 public:
18  virtual void setRxRDY(bool status, EmuTime::param time) = 0;
19  virtual void setDTR(bool status, EmuTime::param time) = 0;
20  virtual void setRTS(bool status, EmuTime::param time) = 0;
21  virtual bool getDSR(EmuTime::param time) = 0;
22  virtual bool getCTS(EmuTime::param time) = 0; // TODO use this
23  virtual void signal(EmuTime::param time) = 0;
24 
25 protected:
28 };
29 
30 class I8251 final : public SerialDataInterface
31 {
32 public:
33  I8251(Scheduler& scheduler, I8251Interface& interf, EmuTime::param time);
34 
35  void reset(EmuTime::param time);
36  byte readIO(word port, EmuTime::param time);
37  byte peekIO(word port, EmuTime::param time) const;
38  void writeIO(word port, byte value, EmuTime::param time);
39  ClockPin& getClockPin() { return clock; }
40  bool isRecvReady() { return recvReady; }
41  bool isRecvEnabled();
42 
43  // SerialDataInterface
44  void setDataBits(DataBits bits) override { recvDataBits = bits; }
45  void setStopBits(StopBits bits) override { recvStopBits = bits; }
46  void setParityBit(bool enable, ParityBit parity) override;
47  void recvByte(byte value, EmuTime::param time) override;
48 
49  // Schedulable
50  struct SyncRecv : Schedulable {
51  friend class I8251;
53  void executeUntil(EmuTime::param time) override {
54  auto& i8251 = OUTER(I8251, syncRecv);
55  i8251.execRecv(time);
56  }
57  } syncRecv;
59  friend class I8251;
61  void executeUntil(EmuTime::param time) override {
62  auto& i8251 = OUTER(I8251, syncTrans);
63  i8251.execTrans(time);
64  }
65  } syncTrans;
66  void execRecv(EmuTime::param time);
67  void execTrans(EmuTime::param time);
68 
69  template<typename Archive>
70  void serialize(Archive& ar, unsigned version);
71 
72  // public for serialize
73  enum CmdFaze {
75  };
76 
77 private:
78  void setMode(byte mode);
79  void writeCommand(byte value, EmuTime::param time);
80  byte readStatus(EmuTime::param time);
81  byte readTrans(EmuTime::param time);
82  void writeTrans(byte value, EmuTime::param time);
83  void send(byte value, EmuTime::param time);
84 
85  I8251Interface& interf;
86  ClockPin clock;
87  unsigned charLength;
88 
89  CmdFaze cmdFaze;
90  SerialDataInterface::DataBits recvDataBits;
91  SerialDataInterface::StopBits recvStopBits;
92  SerialDataInterface::ParityBit recvParityBit;
93  bool recvParityEnabled;
94  byte recvBuf;
95  bool recvReady;
96 
97  byte sendByte;
98  byte sendBuffer;
99 
100  byte status;
101  byte command;
102  byte mode;
103  byte sync1, sync2;
104 };
106 
107 } // namespace openmsx
108 
109 #endif
virtual void signal(EmuTime::param time)=0
bool isRecvEnabled()
Definition: I8251.cc:318
ClockPin & getClockPin()
Definition: I8251.hh:39
void setStopBits(StopBits bits) override
Definition: I8251.hh:45
SyncTrans(Scheduler &s)
Definition: I8251.hh:60
void setParityBit(bool enable, ParityBit parity) override
Definition: I8251.cc:294
SyncRecv(Scheduler &s)
Definition: I8251.hh:52
virtual bool getCTS(EmuTime::param time)=0
I8251(Scheduler &scheduler, I8251Interface &interf, EmuTime::param time)
Definition: I8251.cc:49
bool isRecvReady()
Definition: I8251.hh:40
void serialize(Archive &ar, unsigned version)
Definition: I8251.cc:387
virtual void setDTR(bool status, EmuTime::param time)=0
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
void writeIO(word port, byte value, EmuTime::param time)
Definition: I8251.cc:108
virtual void setRTS(bool status, EmuTime::param time)=0
byte readIO(word port, EmuTime::param time)
Definition: I8251.cc:79
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::I8251::SyncTrans syncTrans
unsigned char byte
8 bit unsigned integer
Definition: openmsx.hh:25
void reset(EmuTime::param time)
Definition: I8251.cc:57
void execTrans(EmuTime::param time)
Definition: I8251.cc:340
void executeUntil(EmuTime::param time) override
When the previously registered syncPoint is reached, this method gets called.
Definition: I8251.hh:61
void executeUntil(EmuTime::param time) override
When the previously registered syncPoint is reached, this method gets called.
Definition: I8251.hh:53
openmsx::I8251::SyncRecv syncRecv
void execRecv(EmuTime::param time)
Definition: I8251.cc:333
#define OUTER(type, member)
Definition: outer.hh:38
void setDataBits(DataBits bits) override
Definition: I8251.hh:44
void recvByte(byte value, EmuTime::param time) override
Definition: I8251.cc:300
byte peekIO(word port, EmuTime::param time) const
Definition: I8251.cc:95
virtual void setRxRDY(bool status, EmuTime::param time)=0
virtual bool getDSR(EmuTime::param time)=0
unsigned short word
16 bit unsigned integer
Definition: openmsx.hh:28