openMSX
MSXFacMidiInterface.cc
Go to the documentation of this file.
2#include "MidiInDevice.hh"
3#include "outer.hh"
4#include "serialize.hh"
5
6namespace openmsx {
7
9 : MSXDevice(config)
10 , MidiInConnector(MSXDevice::getPluggingController(), MSXDevice::getName() + "-in")
11 , outConnector (MSXDevice::getPluggingController(), MSXDevice::getName() + "-out")
12 , i8251(getScheduler(), interface, getCurrentTime())
13{
14 EmuTime::param time = getCurrentTime();
15 static constexpr auto period = EmuDuration::hz(500000); // 500 kHz
16 i8251.getClockPin().setPeriodicState(period, period / 2, time);
17 reset(time);
18}
19
20void MSXFacMidiInterface::reset(EmuTime::param time)
21{
22 i8251.reset(time);
23}
24
25byte 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
32byte MSXFacMidiInterface::peekIO(word port, EmuTime::param time) const
33{
34 return i8251.peekIO(port & 1, time);
35}
36
37void 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
46void MSXFacMidiInterface::Interface::setRxRDY(bool /*status*/, EmuTime::param /*time*/)
47{
48}
49
50void MSXFacMidiInterface::Interface::setDTR(bool /*status*/, EmuTime::param /*time*/)
51{
52}
53
54void MSXFacMidiInterface::Interface::setRTS(bool /*status*/, EmuTime::param /*time*/)
55{
56}
57
58bool MSXFacMidiInterface::Interface::getDSR(EmuTime::param /*time*/)
59{
60 return true;
61}
62
63bool MSXFacMidiInterface::Interface::getCTS(EmuTime::param /*time*/)
64{
65 return true;
66}
67
68void MSXFacMidiInterface::Interface::setDataBits(DataBits bits)
69{
70 auto& midi = OUTER(MSXFacMidiInterface, interface);
71 midi.outConnector.setDataBits(bits);
72}
73
74void MSXFacMidiInterface::Interface::setStopBits(StopBits bits)
75{
76 auto& midi = OUTER(MSXFacMidiInterface, interface);
77 midi.outConnector.setStopBits(bits);
78}
79
80void MSXFacMidiInterface::Interface::setParityBit(bool enable, ParityBit parity)
81{
82 auto& midi = OUTER(MSXFacMidiInterface, interface);
83 midi.outConnector.setParityBit(enable, parity);
84}
85
86void MSXFacMidiInterface::Interface::recvByte(byte value, EmuTime::param time)
87{
88 auto& midi = OUTER(MSXFacMidiInterface, interface);
89 midi.outConnector.recvByte(value, time);
90}
91
92void MSXFacMidiInterface::Interface::signal(EmuTime::param time)
93{
94 auto& midi = OUTER(MSXFacMidiInterface, interface);
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
126void MSXFacMidiInterface::recvByte(byte value, EmuTime::param time)
127{
128 i8251.recvByte(value, time);
129}
130
131
132template<typename Archive>
133void 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}
142
143} // namespace openmsx
void setPeriodicState(EmuDuration::param total, EmuDuration::param hi, EmuTime::param time)
Definition: ClockPin.cc:33
static constexpr EmuDuration hz(unsigned x)
Definition: EmuDuration.hh:47
byte peekIO(word port, EmuTime::param time) const
Definition: I8251.cc:86
void setStopBits(StopBits bits) override
Definition: I8251.hh:45
bool isRecvReady() const
Definition: I8251.hh:40
void recvByte(byte value, EmuTime::param time) override
Definition: I8251.cc:261
ClockPin & getClockPin()
Definition: I8251.hh:39
void setParityBit(bool enable, ParityBit parity) override
Definition: I8251.cc:255
void writeIO(word port, byte value, EmuTime::param time)
Definition: I8251.cc:96
void reset(EmuTime::param time)
Definition: I8251.cc:55
void setDataBits(DataBits bits) override
Definition: I8251.hh:44
byte readIO(word port, EmuTime::param time)
Definition: I8251.cc:77
bool isRecvEnabled() const
Definition: I8251.cc:279
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:34
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:125
void setDataBits(DataBits bits) override
void recvByte(byte value, EmuTime::param time) override
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.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
MSXFacMidiInterface(const DeviceConfig &config)
void serialize(Archive &ar, unsigned version)
void setParityBit(bool enable, ParityBit parity) override
void setStopBits(StopBits bits) override
void reset(EmuTime::param time) override
This method is called on reset.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define OUTER(type, member)
Definition: outer.hh:41
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021