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
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
bool acceptsData() override
Definition: MSXMidi.cc:374
MSXMidi(const DeviceConfig &config)
Definition: MSXMidi.cc:17
void recvByte(byte value, EmuTime::param time) override
Definition: MSXMidi.cc:394
void serialize(Archive &ar, unsigned version)
Definition: MSXMidi.cc:401
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:79
void setDataBits(DataBits bits) override
Definition: MSXMidi.cc:379
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXMidi.cc:103
bool ready() override
Definition: MSXMidi.cc:369
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXMidi.cc:389
void setStopBits(StopBits bits) override
Definition: MSXMidi.cc:384
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXMidi.cc:64
~MSXMidi() override
Definition: MSXMidi.cc:56
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:127
This file implemented 3 utility functions:
Definition: Autofire.cc:5
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)