openMSX
MC6850.hh
Go to the documentation of this file.
1 #ifndef MC6850_HH
2 #define MC6850_HH
3 
4 #include "MSXDevice.hh"
5 #include "DynamicClock.hh"
6 #include "IRQHelper.hh"
7 #include "MidiInConnector.hh"
8 #include "MidiOutConnector.hh"
9 #include "Schedulable.hh"
10 #include "openmsx.hh"
11 #include "outer.hh"
12 #include "serialize_meta.hh"
13 
14 namespace openmsx {
15 
16 class Scheduler;
17 
18 class MC6850 final : public MSXDevice, public MidiInConnector
19 {
20 public:
21  explicit MC6850(const DeviceConfig& config);
22 
23  // MSXDevice
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 
29  template<typename Archive>
30  void serialize(Archive& ar, unsigned version);
31 
32 private:
33  byte readStatusReg();
34  byte peekStatusReg() const;
35  byte readDataReg();
36  byte peekDataReg() const;
37  void writeControlReg(byte value, EmuTime::param time);
38  void writeDataReg (byte value, EmuTime::param time);
39  void setDataFormat();
40 
41  // MidiInConnector
42  bool ready() override;
43  bool acceptsData() override;
44  void setDataBits(DataBits bits) override;
45  void setStopBits(StopBits bits) override;
46  void setParityBit(bool enable, ParityBit parity) override;
47  void recvByte(byte value, EmuTime::param time) override;
48 
49  // Schedulable
50  struct SyncRecv final : Schedulable {
51  friend class MC6850;
52  explicit SyncRecv(Scheduler& s) : Schedulable(s) {}
53  void executeUntil(EmuTime::param time) override {
54  auto& mc6850 = OUTER(MC6850, syncRecv);
55  mc6850.execRecv(time);
56  }
57  } syncRecv;
58  struct SyncTrans final : Schedulable {
59  friend class MC6850;
60  explicit SyncTrans(Scheduler& s) : Schedulable(s) {}
61  void executeUntil(EmuTime::param time) override {
62  auto& mc6850 = OUTER(MC6850, syncTrans);
63  mc6850.execTrans(time);
64  }
65  } syncTrans;
66  void execRecv (EmuTime::param time);
67  void execTrans(EmuTime::param time);
68 
69  // External clock of 500kHz, divided by 1, 16 or 64.
70  // Transmitted bits are synced to this clock
71  DynamicClock txClock;
72 
73  IRQHelper rxIRQ;
74  IRQHelper txIRQ;
75  bool rxReady;
76  bool txShiftRegValid; //<! True iff txShiftReg contains a valid value
77  bool pendingOVRN; //<! Overrun detected but not yet reported.
78  byte rxDataReg; //<! Byte received from MIDI in connector.
79  byte txDataReg; //<! Next to-be-sent byte.
80  byte txShiftReg; //<! Byte currently being sent.
81  byte controlReg;
82  byte statusReg;
83  byte charLen; //<! #start- + #data- + #parity- + #stop-bits
84 
85  MidiOutConnector outConnector;
86 };
88 
89 } // namespace openmsx
90 
91 #endif
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MC6850.cc:98
MC6850(const DeviceConfig &config)
Definition: MC6850.cc:82
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MC6850.cc:127
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
Represents a clock with a variable frequency.
Definition: DynamicClock.hh:15
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MC6850.cc:115
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
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: MC6850.cc:139
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define OUTER(type, member)
Definition: outer.hh:38
void serialize(Archive &ar, unsigned version)
Definition: MC6850.cc:355