openMSX
MSXFacMidiInterface.cc
Go to the documentation of this file.
1 #include "MSXFacMidiInterface.hh"
2 #include "MidiInDevice.hh"
3 #include "outer.hh"
4 #include "serialize.hh"
5 
6 namespace openmsx {
7 
9  : MSXDevice(config)
10  , MidiInConnector(MSXDevice::getPluggingController(), MSXDevice::getName() + "-in")
11  , outConnector (MSXDevice::getPluggingController(), MSXDevice::getName() + "-out")
12  , i8251(getScheduler(), interf, getCurrentTime())
13 {
14  EmuTime::param time = getCurrentTime();
15  auto period = EmuDuration::hz(500000); // 500 kHz
16  i8251.getClockPin().setPeriodicState(period, period / 2, time);
17  reset(time);
18 }
19 
20 void MSXFacMidiInterface::reset(EmuTime::param time)
21 {
22  i8251.reset(time);
23 }
24 
25 byte MSXFacMidiInterface::readIO(word port, EmuTime::param time)
26 {
27  // 0 -> UART data register
28  // 1 -> UART status register
29  return i8251.readIO(port & 1, time);
30 }
31 
32 byte MSXFacMidiInterface::peekIO(word port, EmuTime::param time) const
33 {
34  return i8251.peekIO(port & 1, time);
35 }
36 
37 void MSXFacMidiInterface::writeIO(word port, byte value, EmuTime::param time)
38 {
39  // 0 -> UART data register
40  // 1 -> UART command register
41  i8251.writeIO(port & 1, value, time);
42 }
43 
44 // I8251Interface (pass calls from I8251 to outConnector)
45 
46 void MSXFacMidiInterface::I8251Interf::setRxRDY(bool /*status*/, EmuTime::param /*time*/)
47 {
48 }
49 
50 void MSXFacMidiInterface::I8251Interf::setDTR(bool /*status*/, EmuTime::param /*time*/)
51 {
52 }
53 
54 void MSXFacMidiInterface::I8251Interf::setRTS(bool /*status*/, EmuTime::param /*time*/)
55 {
56 }
57 
58 bool MSXFacMidiInterface::I8251Interf::getDSR(EmuTime::param /*time*/)
59 {
60  return true;
61 }
62 
63 bool MSXFacMidiInterface::I8251Interf::getCTS(EmuTime::param /*time*/)
64 {
65  return true;
66 }
67 
68 void MSXFacMidiInterface::I8251Interf::setDataBits(DataBits bits)
69 {
70  auto& midi = OUTER(MSXFacMidiInterface, interf);
71  midi.outConnector.setDataBits(bits);
72 }
73 
74 void MSXFacMidiInterface::I8251Interf::setStopBits(StopBits bits)
75 {
76  auto& midi = OUTER(MSXFacMidiInterface, interf);
77  midi.outConnector.setStopBits(bits);
78 }
79 
80 void MSXFacMidiInterface::I8251Interf::setParityBit(bool enable, ParityBit parity)
81 {
82  auto& midi = OUTER(MSXFacMidiInterface, interf);
83  midi.outConnector.setParityBit(enable, parity);
84 }
85 
86 void MSXFacMidiInterface::I8251Interf::recvByte(byte value, EmuTime::param time)
87 {
88  auto& midi = OUTER(MSXFacMidiInterface, interf);
89  midi.outConnector.recvByte(value, time);
90 }
91 
92 void MSXFacMidiInterface::I8251Interf::signal(EmuTime::param time)
93 {
94  auto& midi = OUTER(MSXFacMidiInterface, interf);
95  midi.getPluggedMidiInDev().signal(time);
96 }
97 
98 
99 // MidiInConnector
100 
102 {
103  return i8251.isRecvReady();
104 }
105 
107 {
108  return i8251.isRecvEnabled();
109 }
110 
112 {
113  i8251.setDataBits(bits);
114 }
115 
117 {
118  i8251.setStopBits(bits);
119 }
120 
122 {
123  i8251.setParityBit(enable, parity);
124 }
125 
126 void MSXFacMidiInterface::recvByte(byte value, EmuTime::param time)
127 {
128  i8251.recvByte(value, time);
129 }
130 
131 
132 template<typename Archive>
133 void MSXFacMidiInterface::serialize(Archive& ar, unsigned /*version*/)
134 {
135  ar.template serializeBase<MSXDevice>(*this);
136  ar.template serializeBase<MidiInConnector>(*this);
137  ar.serialize("outConnector", outConnector,
138  "I8251", i8251);
139 }
141 REGISTER_MSXDEVICE(MSXFacMidiInterface, "MSXFacMidiInterface");
142 
143 } // namespace openmsx
MSXFacMidiInterface(const DeviceConfig &config)
static EmuDuration hz(unsigned x)
Definition: EmuDuration.hh:43
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
void setStopBits(StopBits bits) override
bool isRecvEnabled()
Definition: I8251.cc:318
ClockPin & getClockPin()
Definition: I8251.hh:39
byte peekIO(word port, EmuTime::param time) const
Definition: I8251.cc:95
void setStopBits(StopBits bits) override
Definition: I8251.hh:45
void setParityBit(bool enable, ParityBit parity) override
Definition: I8251.cc:294
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
bool isRecvReady()
Definition: I8251.hh:40
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
void serialize(Archive &ar, unsigned version)
void setDataBits(DataBits bits) override
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:133
void writeIO(word port, byte value, EmuTime::param time)
Definition: I8251.cc:108
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
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void reset(EmuTime::param time) override
This method is called on reset.
void reset(EmuTime::param time)
Definition: I8251.cc:57
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
void recvByte(byte value, EmuTime::param time) override
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1006
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
#define OUTER(type, member)
Definition: outer.hh:38
void setDataBits(DataBits bits) override
Definition: I8251.hh:44
void recvByte(byte value, EmuTime::param time) override
Definition: I8251.cc:300
void setParityBit(bool enable, ParityBit parity) override
void setPeriodicState(EmuDuration::param total, EmuDuration::param hi, EmuTime::param time)
Definition: ClockPin.cc:36
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.