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();
18 
19  void reset(EmuTime::param time) override;
20  byte readIO(word port, EmuTime::param time) override;
21  byte peekIO(word port, EmuTime::param time) const override;
22  void writeIO(word port, byte value, EmuTime::param time) override;
23 
24  // MidiInConnector
25  bool ready() override;
26  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  class Counter0 final : public ClockPinListener {
47  public:
48  explicit Counter0(MSXMidi& midi);
49  void signal(ClockPin& pin, EmuTime::param time) override;
50  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
51  private:
52  MSXMidi& midi;
53  } cntr0; // counter 0 clock pin
54 
55  class Counter2 final : public ClockPinListener {
56  public:
57  explicit Counter2(MSXMidi& midi);
58  void signal(ClockPin& pin, EmuTime::param time) override;
59  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
60  private:
61  MSXMidi& midi;
62  } cntr2; // counter 2 clock pin
63 
64  class I8251Interf final : public I8251Interface {
65  public:
66  explicit I8251Interf(MSXMidi& midi);
67  void setRxRDY(bool status, EmuTime::param time) override;
68  void setDTR(bool status, EmuTime::param time) override;
69  void setRTS(bool status, EmuTime::param time) override;
70  bool getDSR(EmuTime::param time) override;
71  bool getCTS(EmuTime::param time) override;
72  void setDataBits(DataBits bits) override;
73  void setStopBits(StopBits bits) override;
74  void setParityBit(bool enable, ParityBit parity) override;
75  void recvByte(byte value, EmuTime::param time) override;
76  void signal(EmuTime::param time) override;
77  private:
78  MSXMidi& midi;
79  } interf;
80 
81  IRQHelper timerIRQ;
82  IRQHelper rxrdyIRQ;
83  bool timerIRQlatch;
84  bool timerIRQenabled;
85  bool rxrdyIRQlatch;
86  bool rxrdyIRQenabled;
87 
88  const bool isExternalMSXMIDI;
89  bool isEnabled; /* EN bit */
90  bool isLimitedTo8251; /* inverse of E8 bit */
91 
92  // must come last
93  MidiOutConnector outConnector;
94  I8251 i8251;
95  I8254 i8254;
96 };
98 
99 } // namespace openmsx
100 
101 #endif
bool ready() override
Definition: MSXMidi.cc:385
void serialize(Archive &ar, unsigned version)
Definition: MSXMidi.cc:417
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXMidi.cc:104
MSXMidi(const DeviceConfig &config)
Definition: MSXMidi.cc:16
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXMidi.cc:66
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:128
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXMidi.cc:405
void setStopBits(StopBits bits) override
Definition: MSXMidi.cc:400
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:32
unsigned char byte
8 bit unsigned integer
Definition: openmsx.hh:25
void setDataBits(DataBits bits) override
Definition: MSXMidi.cc:395
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:80
void recvByte(byte value, EmuTime::param time) override
Definition: MSXMidi.cc:410
bool acceptsData() override
Definition: MSXMidi.cc:390
unsigned short word
16 bit unsigned integer
Definition: openmsx.hh:28