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 
8 namespace openmsx {
9 
10 class MSXMidiCounter0;
11 class MSXMidiCounter2;
12 class MSXMidiI8251Interf;
13 class I8254;
14 class I8251;
15 class MidiOutConnector;
16 
17 class MSXMidi final : public MSXDevice, public MidiInConnector
18 {
19 public:
20  explicit MSXMidi(const DeviceConfig& config);
21  ~MSXMidi();
22 
23  void reset(EmuTime::param time) override;
24  byte readIO(word port, EmuTime::param time) override;
25  byte peekIO(word port, EmuTime::param time) const override;
26  void writeIO(word port, byte value, EmuTime::param time) override;
27 
28  // MidiInConnector
29  bool ready() override;
30  bool acceptsData() override;
31  void setDataBits(DataBits bits) override;
32  void setStopBits(StopBits bits) override;
33  void setParityBit(bool enable, ParityBit parity) override;
34  void recvByte(byte value, EmuTime::param time) override;
35 
36  template<typename Archive>
37  void serialize(Archive& ar, unsigned version);
38 
39 private:
40  void setTimerIRQ(bool status, EmuTime::param time);
41  void enableTimerIRQ(bool enabled, EmuTime::param time);
42  void updateEdgeEvents(EmuTime::param time);
43  void setRxRDYIRQ(bool status);
44  void enableRxRDYIRQ(bool enabled);
45 
46  void registerIOports(byte value);
47  void registerRange(byte port, unsigned num);
48  void unregisterRange(byte port, unsigned num);
49 
50  const std::unique_ptr<MSXMidiCounter0> cntr0; // counter 0 clock pin
51  const std::unique_ptr<MSXMidiCounter2> cntr2; // counter 2 clock pin
52  const std::unique_ptr<MSXMidiI8251Interf> interf;
53 
54  IRQHelper timerIRQ;
55  IRQHelper rxrdyIRQ;
56  bool timerIRQlatch;
57  bool timerIRQenabled;
58  bool rxrdyIRQlatch;
59  bool rxrdyIRQenabled;
60 
61  const bool isExternalMSXMIDI;
62  bool isEnabled; /* EN bit */
63  bool isLimitedTo8251; /* inverse of E8 bit */
64 
65  // must come last
66  const std::unique_ptr<MidiOutConnector> outConnector;
67  const std::unique_ptr<I8251> i8251;
68  const std::unique_ptr<I8254> i8254;
69 
70  friend class MSXMidiCounter0;
71  friend class MSXMidiCounter2;
72  friend class MSXMidiI8251Interf;
73 };
75 
76 } // namespace openmsx
77 
78 #endif
bool ready() override
Definition: MSXMidi.cc:445
unsigned char byte
8 bit unsigned integer
Definition: openmsx.hh:33
void serialize(Archive &ar, unsigned version)
Definition: MSXMidi.cc:477
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXMidi.cc:152
MSXMidi(const DeviceConfig &config)
Definition: MSXMidi.cc:61
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXMidi.cc:114
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
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:176
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXMidi.cc:465
void setStopBits(StopBits bits) override
Definition: MSXMidi.cc:460
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:32
unsigned short word
16 bit unsigned integer
Definition: openmsx.hh:38
void setDataBits(DataBits bits) override
Definition: MSXMidi.cc:455
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:128
void recvByte(byte value, EmuTime::param time) override
Definition: MSXMidi.cc:470
bool acceptsData() override
Definition: MSXMidi.cc:450