openMSX
MSXMidi.hh
Go to the documentation of this file.
1 #ifndef MSXMIDI_HH
2 #define MSXMIDI_HH
3 
4 #include "MSXDevice.hh"
5 #include "IRQHelper.hh"
6 #include "MidiInConnector.hh"
7 #include "MidiOutConnector.hh"
8 #include "I8251.hh"
9 #include "I8254.hh"
10 
11 namespace openmsx {
12 
13 class MSXMidi final : public MSXDevice, public MidiInConnector
14 {
15 public:
16  explicit MSXMidi(const DeviceConfig& config);
17  ~MSXMidi() override;
18 
19  void reset(EmuTime::param time) override;
20  [[nodiscard]] byte readIO(word port, EmuTime::param time) override;
21  [[nodiscard]] byte peekIO(word port, EmuTime::param time) const override;
22  void writeIO(word port, byte value, EmuTime::param time) override;
23 
24  // MidiInConnector
25  [[nodiscard]] bool ready() override;
26  [[nodiscard]] bool acceptsData() override;
27  void setDataBits(DataBits bits) override;
28  void setStopBits(StopBits bits) override;
29  void setParityBit(bool enable, ParityBit parity) override;
30  void recvByte(byte value, EmuTime::param time) override;
31 
32  template<typename Archive>
33  void serialize(Archive& ar, unsigned version);
34 
35 private:
36  void setTimerIRQ(bool status, EmuTime::param time);
37  void enableTimerIRQ(bool enabled, EmuTime::param time);
38  void updateEdgeEvents(EmuTime::param time);
39  void setRxRDYIRQ(bool status);
40  void enableRxRDYIRQ(bool enabled);
41 
42  void registerIOports(byte value);
43  void registerRange(byte port, unsigned num);
44  void unregisterRange(byte port, unsigned num);
45 
46 private:
47  struct Counter0 final : ClockPinListener {
48  void signal(ClockPin& pin, EmuTime::param time) override;
49  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
50  } cntr0; // counter 0 clock pin
51 
52  struct Counter2 final : ClockPinListener {
53  void signal(ClockPin& pin, EmuTime::param time) override;
54  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
55  } cntr2; // counter 2 clock pin
56 
57  struct I8251Interf final : I8251Interface {
58  void setRxRDY(bool status, EmuTime::param time) override;
59  void setDTR(bool status, EmuTime::param time) override;
60  void setRTS(bool status, EmuTime::param time) override;
61  [[nodiscard]] bool getDSR(EmuTime::param time) override;
62  [[nodiscard]] bool getCTS(EmuTime::param time) override;
63  void setDataBits(DataBits bits) override;
64  void setStopBits(StopBits bits) override;
65  void setParityBit(bool enable, ParityBit parity) override;
66  void recvByte(byte value, EmuTime::param time) override;
67  void signal(EmuTime::param time) override;
68  } interf;
69 
70  IRQHelper timerIRQ;
71  IRQHelper rxrdyIRQ;
72  bool timerIRQlatch;
73  bool timerIRQenabled;
74  bool rxrdyIRQlatch;
75  bool rxrdyIRQenabled;
76 
77  const bool isExternalMSXMIDI;
78  bool isEnabled; /* EN bit */
79  bool isLimitedTo8251; /* inverse of E8 bit */
80 
81  // must come last
82  MidiOutConnector outConnector;
83  I8251 i8251;
84  I8254 i8254;
85 };
87 
88 } // namespace openmsx
89 
90 #endif
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
I8251.hh
openmsx::MSXMidi::setParityBit
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXMidi.cc:388
openmsx::MidiInConnector
Definition: MidiInConnector.hh:13
openmsx::MSXMidi
Definition: MSXMidi.hh:14
openmsx::ClockPin
Definition: ClockPin.hh:23
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::I8251Interface
Definition: I8251.hh:16
openmsx::MSXMidi::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MSXMidi.cc:78
openmsx::MSXMidi::setStopBits
void setStopBits(StopBits bits) override
Definition: MSXMidi.cc:383
openmsx::IntHelper< IRQSource >
openmsx::MSXMidi::ready
bool ready() override
Definition: MSXMidi.cc:368
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::MidiOutConnector
Definition: MidiOutConnector.hh:12
MidiInConnector.hh
openmsx::I8254
Definition: I8254.hh:21
MSXDevice.hh
openmsx::MSXMidi::recvByte
void recvByte(byte value, EmuTime::param time) override
Definition: MSXMidi.cc:393
openmsx::MSXMidi::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: MSXMidi.cc:126
openmsx::SerialDataInterface::StopBits
StopBits
Definition: SerialDataInterface.hh:15
openmsx::ClockPinListener
Definition: ClockPin.hh:13
openmsx::SerialDataInterface::DataBits
DataBits
Definition: SerialDataInterface.hh:12
openmsx::MSXMidi::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXMidi.cc:63
openmsx::MSXMidi::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXMidi.cc:102
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXMidi::acceptsData
bool acceptsData() override
Definition: MSXMidi.cc:373
MidiOutConnector.hh
openmsx::I8251
Definition: I8251.hh:31
openmsx::SerialDataInterface::ParityBit
ParityBit
Definition: SerialDataInterface.hh:19
IRQHelper.hh
openmsx::MSXMidi::~MSXMidi
~MSXMidi() override
Definition: MSXMidi.cc:55
I8254.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::MSXMidi::setDataBits
void setDataBits(DataBits bits) override
Definition: MSXMidi.cc:378
openmsx::MSXMidi::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXMidi.cc:400
openmsx::MSXMidi::MSXMidi
MSXMidi(const DeviceConfig &config)
Definition: MSXMidi.cc:16