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  static constexpr 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
openmsx::I8251::setParityBit
void setParityBit(bool enable, ParityBit parity) override
Definition: I8251.cc:294
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:31
openmsx::ClockPin::setPeriodicState
void setPeriodicState(EmuDuration::param total, EmuDuration::param hi, EmuTime::param time)
Definition: ClockPin.cc:36
openmsx::I8251::peekIO
byte peekIO(word port, EmuTime::param time) const
Definition: I8251.cc:95
openmsx::MidiInConnector
Definition: MidiInConnector.hh:12
openmsx::MSXFacMidiInterface
Definition: MSXFacMidiInterface.hh:11
serialize.hh
openmsx::I8251::setDataBits
void setDataBits(DataBits bits) override
Definition: I8251.hh:44
openmsx::I8251::setStopBits
void setStopBits(StopBits bits) override
Definition: I8251.hh:45
openmsx::MSXFacMidiInterface::ready
bool ready() override
Definition: MSXFacMidiInterface.cc:101
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
openmsx::I8251::readIO
byte readIO(word port, EmuTime::param time)
Definition: I8251.cc:79
openmsx::MSXFacMidiInterface::acceptsData
bool acceptsData() override
Definition: MSXFacMidiInterface.cc:106
openmsx::MSXFacMidiInterface::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXFacMidiInterface.cc:20
MidiInDevice.hh
openmsx::MSXFacMidiInterface::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MSXFacMidiInterface.cc:25
openmsx::I8251::reset
void reset(EmuTime::param time)
Definition: I8251.cc:57
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXFacMidiInterface::MSXFacMidiInterface
MSXFacMidiInterface(const DeviceConfig &config)
Definition: MSXFacMidiInterface.cc:8
openmsx::MSXFacMidiInterface::writeIO
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: MSXFacMidiInterface.cc:37
OUTER
#define OUTER(type, member)
Definition: outer.hh:41
openmsx::MSXFacMidiInterface
MSXFacMidiInterface
Definition: MSXFacMidiInterface.cc:140
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:740
openmsx::MSXFacMidiInterface::recvByte
void recvByte(byte value, EmuTime::param time) override
Definition: MSXFacMidiInterface.cc:126
openmsx::MSXDevice::getCurrentTime
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:131
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::I8251::writeIO
void writeIO(word port, byte value, EmuTime::param time)
Definition: I8251.cc:108
openmsx::SerialDataInterface::StopBits
StopBits
Definition: SerialDataInterface.hh:15
openmsx::SerialDataInterface::DataBits
DataBits
Definition: SerialDataInterface.hh:12
openmsx::EmuDuration::hz
static constexpr EmuDuration hz(unsigned x)
Definition: EmuDuration.hh:45
outer.hh
openmsx::I8251::isRecvEnabled
bool isRecvEnabled() const
Definition: I8251.cc:318
openmsx::MSXFacMidiInterface::setParityBit
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXFacMidiInterface.cc:121
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXFacMidiInterface::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXFacMidiInterface.cc:32
MSXFacMidiInterface.hh
openmsx::I8251::getClockPin
ClockPin & getClockPin()
Definition: I8251.hh:39
openmsx::MSXFacMidiInterface::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXFacMidiInterface.cc:133
openmsx::SerialDataInterface::ParityBit
ParityBit
Definition: SerialDataInterface.hh:19
openmsx::MSXFacMidiInterface::setStopBits
void setStopBits(StopBits bits) override
Definition: MSXFacMidiInterface.cc:116
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::I8251::recvByte
void recvByte(byte value, EmuTime::param time) override
Definition: I8251.cc:300
openmsx::I8251::isRecvReady
bool isRecvReady() const
Definition: I8251.hh:40
openmsx::MSXFacMidiInterface::setDataBits
void setDataBits(DataBits bits) override
Definition: MSXFacMidiInterface.cc:111