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 "openmsx.hh"
10 
11 namespace openmsx {
12 
14 {
15 public:
16  virtual void setRxRDY(bool status, EmuTime::param time) = 0;
17  virtual void setDTR(bool status, EmuTime::param time) = 0;
18  virtual void setRTS(bool status, EmuTime::param time) = 0;
19  virtual bool getDSR(EmuTime::param time) = 0;
20  virtual bool getCTS(EmuTime::param time) = 0; // TODO use this
21  virtual void signal(EmuTime::param time) = 0;
22 
23 protected:
26 };
27 
28 class I8251 final : public SerialDataInterface, public Schedulable
29 {
30 public:
31  I8251(Scheduler& scheduler, I8251Interface& interf, EmuTime::param time);
32 
33  void reset(EmuTime::param time);
34  byte readIO(word port, EmuTime::param time);
35  byte peekIO(word port, EmuTime::param time) const;
36  void writeIO(word port, byte value, EmuTime::param time);
37  ClockPin& getClockPin() { return clock; }
38  bool isRecvReady() { return recvReady; }
39  bool isRecvEnabled();
40 
41  // SerialDataInterface
42  void setDataBits(DataBits bits) override { recvDataBits = bits; }
43  void setStopBits(StopBits bits) override { recvStopBits = bits; }
44  void setParityBit(bool enable, ParityBit parity) override;
45  void recvByte(byte value, EmuTime::param time) override;
46 
47  // Schedulable
48  void executeUntil(EmuTime::param time, int userData) override;
49 
50  template<typename Archive>
51  void serialize(Archive& ar, unsigned version);
52 
53  // public for serialize
54  enum CmdFaze {
56  };
57 
58 private:
59  void setMode(byte mode);
60  void writeCommand(byte value, EmuTime::param time);
61  byte readStatus(EmuTime::param time);
62  byte readTrans(EmuTime::param time);
63  void writeTrans(byte value, EmuTime::param time);
64  void send(byte value, EmuTime::param time);
65 
66  I8251Interface& interf;
67  ClockPin clock;
68  unsigned charLength;
69 
70  CmdFaze cmdFaze;
71  SerialDataInterface::DataBits recvDataBits;
72  SerialDataInterface::StopBits recvStopBits;
73  SerialDataInterface::ParityBit recvParityBit;
74  bool recvParityEnabled;
75  byte recvBuf;
76  bool recvReady;
77 
78  byte sendByte;
79  byte sendBuffer;
80 
81  byte status;
82  byte command;
83  byte mode;
84  byte sync1, sync2;
85 };
86 
87 } // namespace openmsx
88 
89 #endif
virtual void signal(EmuTime::param time)=0
bool isRecvEnabled()
Definition: I8251.cc:320
ClockPin & getClockPin()
Definition: I8251.hh:37
void setStopBits(StopBits bits) override
Definition: I8251.hh:43
void setParityBit(bool enable, ParityBit parity) override
Definition: I8251.cc:296
unsigned char byte
8 bit unsigned integer
Definition: openmsx.hh:33
virtual bool getCTS(EmuTime::param time)=0
I8251(Scheduler &scheduler, I8251Interface &interf, EmuTime::param time)
Definition: I8251.cc:53
bool isRecvReady()
Definition: I8251.hh:38
void serialize(Archive &ar, unsigned version)
Definition: I8251.cc:391
void executeUntil(EmuTime::param time, int userData) override
When the previously registered syncPoint is reached, this method gets called.
Definition: I8251.cc:335
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:16
void writeIO(word port, byte value, EmuTime::param time)
Definition: I8251.cc:110
virtual void setRTS(bool status, EmuTime::param time)=0
byte readIO(word port, EmuTime::param time)
Definition: I8251.cc:81
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:7
unsigned short word
16 bit unsigned integer
Definition: openmsx.hh:38
void reset(EmuTime::param time)
Definition: I8251.cc:59
void setDataBits(DataBits bits) override
Definition: I8251.hh:42
void recvByte(byte value, EmuTime::param time) override
Definition: I8251.cc:302
byte peekIO(word port, EmuTime::param time) const
Definition: I8251.cc:97
virtual void setRxRDY(bool status, EmuTime::param time)=0
virtual bool getDSR(EmuTime::param time)=0