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
12namespace openmsx {
13
14class Scheduler;
15
16class MC6850 final : public MidiInConnector
17{
18public:
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
32private:
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 = 0; //<! Next to-be-sent byte.
75 byte txShiftReg = 0; //<! 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
Represents a clock with a variable frequency.
byte readDataReg()
Definition MC6850.cc:103
byte peekStatusReg() const
Definition MC6850.cc:96
void reset(EmuTime::param time)
Definition MC6850.cc:74
void writeControlReg(byte value, EmuTime::param time)
Definition MC6850.cc:120
byte readStatusReg() const
Definition MC6850.cc:91
void writeDataReg(byte value, EmuTime::param time)
Definition MC6850.cc:177
byte peekDataReg() const
Definition MC6850.cc:115
void serialize(Archive &ar, unsigned version)
Definition MC6850.cc:295
Every class that wants to get scheduled at some point must inherit from this class.
This file implemented 3 utility functions:
Definition Autofire.cc:9
#define OUTER(type, member)
Definition outer.hh:41
#define SERIALIZE_CLASS_VERSION(CLASS, VERSION)