openMSX
MC6850.hh
Go to the documentation of this file.
1 #ifndef MC6850_HH
2 #define MC6850_HH
3 
4 #include "DynamicClock.hh"
5 #include "IRQHelper.hh"
6 #include "MidiInConnector.hh"
7 #include "MidiOutConnector.hh"
8 #include "Schedulable.hh"
9 #include "openmsx.hh"
10 #include "outer.hh"
11 
12 namespace openmsx {
13 
14 class Scheduler;
15 
16 class MC6850 final : public MidiInConnector
17 {
18 public:
19  MC6850(const std::string& name, MSXMotherBoard& motherBoard, unsigned clockFreq);
20  void reset(EmuTime::param time);
21 
22  [[nodiscard]] byte readStatusReg() const;
23  [[nodiscard]] byte peekStatusReg() const;
24  [[nodiscard]] byte readDataReg();
25  [[nodiscard]] byte peekDataReg() const;
26  void writeControlReg(byte value, EmuTime::param time);
27  void writeDataReg (byte value, EmuTime::param time);
28 
29  template<typename Archive>
30  void serialize(Archive& ar, unsigned version);
31 
32 private:
33  void setDataFormat();
34 
35  // MidiInConnector
36  [[nodiscard]] bool ready() override;
37  [[nodiscard]] bool acceptsData() override;
38  void setDataBits(DataBits bits) override;
39  void setStopBits(StopBits bits) override;
40  void setParityBit(bool enable, ParityBit parity) override;
41  void recvByte(byte value, EmuTime::param time) override;
42 
43  // Schedulable
44  struct SyncRecv final : Schedulable {
45  friend class MC6850;
46  explicit SyncRecv(Scheduler& s) : Schedulable(s) {}
47  void executeUntil(EmuTime::param time) override {
48  auto& mc6850 = OUTER(MC6850, syncRecv);
49  mc6850.execRecv(time);
50  }
51  } syncRecv;
52  struct SyncTrans final : Schedulable {
53  friend class MC6850;
54  explicit SyncTrans(Scheduler& s) : Schedulable(s) {}
55  void executeUntil(EmuTime::param time) override {
56  auto& mc6850 = OUTER(MC6850, syncTrans);
57  mc6850.execTrans(time);
58  }
59  } syncTrans;
60  void execRecv (EmuTime::param time);
61  void execTrans(EmuTime::param time);
62 
63  // External clock, divided by 1, 16 or 64.
64  // Transmitted bits are synced to this clock
65  DynamicClock txClock;
66  const unsigned clockFreq;
67 
68  IRQHelper rxIRQ;
69  IRQHelper txIRQ;
70  bool rxReady;
71  bool txShiftRegValid; //<! True iff txShiftReg contains a valid value
72  bool pendingOVRN; //<! Overrun detected but not yet reported.
73  byte rxDataReg; //<! Byte received from MIDI in connector.
74  byte txDataReg; //<! Next to-be-sent byte.
75  byte txShiftReg; //<! Byte currently being sent.
76  byte controlReg;
77  byte statusReg;
78  byte charLen; //<! #start- + #data- + #parity- + #stop-bits
79 
80  MidiOutConnector outConnector;
81 };
83 
84 } // namespace openmsx
85 
86 #endif
openmsx.hh
openmsx::MidiInConnector
Definition: MidiInConnector.hh:13
openmsx::MC6850::reset
void reset(EmuTime::param time)
Definition: MC6850.cc:75
openmsx::Scheduler
Definition: Scheduler.hh:34
openmsx::Schedulable
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
openmsx::IntHelper< IRQSource >
Schedulable.hh
openmsx::MC6850
Definition: MC6850.hh:17
openmsx::MC6850::writeDataReg
void writeDataReg(byte value, EmuTime::param time)
Definition: MC6850.cc:178
openmsx::MC6850::MC6850
MC6850(const std::string &name, MSXMotherBoard &motherBoard, unsigned clockFreq)
Definition: MC6850.cc:59
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::DynamicClock
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:17
openmsx::MC6850::peekStatusReg
byte peekStatusReg() const
Definition: MC6850.cc:97
openmsx::MidiOutConnector
Definition: MidiOutConnector.hh:12
OUTER
#define OUTER(type, member)
Definition: outer.hh:41
MidiInConnector.hh
openmsx::MC6850::readStatusReg
byte readStatusReg() const
Definition: MC6850.cc:92
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:61
openmsx::MC6850::writeControlReg
void writeControlReg(byte value, EmuTime::param time)
Definition: MC6850.cc:121
openmsx::SerialDataInterface::StopBits
StopBits
Definition: SerialDataInterface.hh:15
openmsx::SerialDataInterface::DataBits
DataBits
Definition: SerialDataInterface.hh:12
outer.hh
openmsx::Schedulable
Schedulable
Definition: Schedulable.cc:69
MidiOutConnector.hh
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:132
openmsx::SerialDataInterface::ParityBit
ParityBit
Definition: SerialDataInterface.hh:19
DynamicClock.hh
openmsx::MC6850::serialize
void serialize(Archive &ar, unsigned version)
Definition: MC6850.cc:296
IRQHelper.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MC6850::peekDataReg
byte peekDataReg() const
Definition: MC6850.cc:116
openmsx::MC6850::readDataReg
byte readDataReg()
Definition: MC6850.cc:104