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  struct Counter0 final : ClockPinListener {
47  void signal(ClockPin& pin, EmuTime::param time) override;
48  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
49  } cntr0; // counter 0 clock pin
50 
51  struct Counter2 final : ClockPinListener {
52  void signal(ClockPin& pin, EmuTime::param time) override;
53  void signalPosEdge(ClockPin& pin, EmuTime::param time) override;
54  } cntr2; // counter 2 clock pin
55 
56  struct I8251Interf final : I8251Interface {
57  void setRxRDY(bool status, EmuTime::param time) override;
58  void setDTR(bool status, EmuTime::param time) override;
59  void setRTS(bool status, EmuTime::param time) override;
60  bool getDSR(EmuTime::param time) override;
61  bool getCTS(EmuTime::param time) override;
62  void setDataBits(DataBits bits) override;
63  void setStopBits(StopBits bits) override;
64  void setParityBit(bool enable, ParityBit parity) override;
65  void recvByte(byte value, EmuTime::param time) override;
66  void signal(EmuTime::param time) override;
67  } interf;
68 
69  IRQHelper timerIRQ;
70  IRQHelper rxrdyIRQ;
71  bool timerIRQlatch;
72  bool timerIRQenabled;
73  bool rxrdyIRQlatch;
74  bool rxrdyIRQenabled;
75 
76  const bool isExternalMSXMIDI;
77  bool isEnabled; /* EN bit */
78  bool isLimitedTo8251; /* inverse of E8 bit */
79 
80  // must come last
81  MidiOutConnector outConnector;
82  I8251 i8251;
83  I8254 i8254;
84 };
86 
87 } // namespace openmsx
88 
89 #endif
bool ready() override
Definition: MSXMidi.cc:380
void serialize(Archive &ar, unsigned version)
Definition: MSXMidi.cc:412
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXMidi.cc:102
MSXMidi(const DeviceConfig &config)
Definition: MSXMidi.cc:17
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXMidi.cc:64
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:126
void setParityBit(bool enable, ParityBit parity) override
Definition: MSXMidi.cc:400
void setStopBits(StopBits bits) override
Definition: MSXMidi.cc:395
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:390
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
void recvByte(byte value, EmuTime::param time) override
Definition: MSXMidi.cc:405
bool acceptsData() override
Definition: MSXMidi.cc:385
unsigned short word
16 bit unsigned integer
Definition: openmsx.hh:28