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 
12 namespace openmsx {
13 
15 {
16 public:
17  virtual void setRxRDY(bool status, EmuTime::param time) = 0;
18  virtual void setDTR(bool status, EmuTime::param time) = 0;
19  virtual void setRTS(bool status, EmuTime::param time) = 0;
20  virtual bool getDSR(EmuTime::param time) = 0;
21  virtual bool getCTS(EmuTime::param time) = 0; // TODO use this
22  virtual void signal(EmuTime::param time) = 0;
23 
24 protected:
27 };
28 
29 class I8251 final : public SerialDataInterface
30 {
31 public:
32  I8251(Scheduler& scheduler, I8251Interface& interf, EmuTime::param time);
33 
34  void reset(EmuTime::param time);
35  byte readIO(word port, EmuTime::param time);
36  byte peekIO(word port, EmuTime::param time) const;
37  void writeIO(word port, byte value, EmuTime::param time);
38  ClockPin& getClockPin() { return clock; }
39  bool isRecvReady() { return recvReady; }
40  bool isRecvEnabled();
41 
42  // SerialDataInterface
43  void setDataBits(DataBits bits) override { recvDataBits = bits; }
44  void setStopBits(StopBits bits) override { recvStopBits = bits; }
45  void setParityBit(bool enable, ParityBit parity) override;
46  void recvByte(byte value, EmuTime::param time) override;
47 
48  // Schedulable
49  struct SyncBase : public Schedulable {
50  SyncBase(Scheduler& s, I8251& i8251_)
51  : Schedulable(s), i8251(i8251_) {}
53  friend class I8251;
54  };
55  struct SyncRecv : public SyncBase {
56  SyncRecv(Scheduler& s, I8251& i) : SyncBase(s, i) {}
57  void executeUntil(EmuTime::param time) override {
58  i8251.execRecv(time);
59  }
60  } syncRecv;
61  struct SyncTrans : public SyncBase {
62  SyncTrans(Scheduler& s, I8251& i) : SyncBase(s, i) {}
63  void executeUntil(EmuTime::param time) override {
64  i8251.execTrans(time);
65  }
66  } syncTrans;
67  void execRecv(EmuTime::param time);
68  void execTrans(EmuTime::param time);
69 
70  template<typename Archive>
71  void serialize(Archive& ar, unsigned version);
72 
73  // public for serialize
74  enum CmdFaze {
76  };
77 
78 private:
79  void setMode(byte mode);
80  void writeCommand(byte value, EmuTime::param time);
81  byte readStatus(EmuTime::param time);
82  byte readTrans(EmuTime::param time);
83  void writeTrans(byte value, EmuTime::param time);
84  void send(byte value, EmuTime::param time);
85 
86  I8251Interface& interf;
87  ClockPin clock;
88  unsigned charLength;
89 
90  CmdFaze cmdFaze;
91  SerialDataInterface::DataBits recvDataBits;
92  SerialDataInterface::StopBits recvStopBits;
93  SerialDataInterface::ParityBit recvParityBit;
94  bool recvParityEnabled;
95  byte recvBuf;
96  bool recvReady;
97 
98  byte sendByte;
99  byte sendBuffer;
100 
101  byte status;
102  byte command;
103  byte mode;
104  byte sync1, sync2;
105 };
107 
108 } // namespace openmsx
109 
110 #endif
virtual void signal(EmuTime::param time)=0
bool isRecvEnabled()
Definition: I8251.cc:318
ClockPin & getClockPin()
Definition: I8251.hh:38
void setStopBits(StopBits bits) override
Definition: I8251.hh:44
void setParityBit(bool enable, ParityBit parity) override
Definition: I8251.cc:294
virtual bool getCTS(EmuTime::param time)=0
I8251(Scheduler &scheduler, I8251Interface &interf, EmuTime::param time)
Definition: I8251.cc:49
bool isRecvReady()
Definition: I8251.hh:39
void serialize(Archive &ar, unsigned version)
Definition: I8251.cc:387
virtual void setDTR(bool status, EmuTime::param time)=0
SyncBase(Scheduler &s, I8251 &i8251_)
Definition: I8251.hh:50
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:63
void executeUntil(EmuTime::param time) override
When the previously registered syncPoint is reached, this method gets called.
Definition: I8251.hh:57
openmsx::I8251::SyncRecv syncRecv
void execRecv(EmuTime::param time)
Definition: I8251.cc:333
void setDataBits(DataBits bits) override
Definition: I8251.hh:43
void recvByte(byte value, EmuTime::param time) override
Definition: I8251.cc:300
byte peekIO(word port, EmuTime::param time) const
Definition: I8251.cc:95
SyncRecv(Scheduler &s, I8251 &i)
Definition: I8251.hh:56
virtual void setRxRDY(bool status, EmuTime::param time)=0
SyncTrans(Scheduler &s, I8251 &i)
Definition: I8251.hh:62
virtual bool getDSR(EmuTime::param time)=0
unsigned short word
16 bit unsigned integer
Definition: openmsx.hh:28