| e8555c89 Andy McCall |
1 |
#ifndef MSXMIDI_HH |
| 2 |
#define MSXMIDI_HH |
| 3 |
|
| 4 |
#include "I8251.hh" |
| 5 |
#include "I8254.hh" |
| 6 |
#include "MidiInConnector.hh" |
| 7 |
#include "MidiOutConnector.hh" |
| 8 |
|
| 9 |
#include "IRQHelper.hh" |
| 10 |
#include "MSXDevice.hh" |
| 11 |
|
| 12 |
namespace openmsx { |
| 13 |
|
| 14 |
class MSXMidi final : public MSXDevice, public MidiInConnector |
| 15 |
{ |
| 16 |
public: |
| 17 |
explicit MSXMidi(const DeviceConfig& config); |
| 18 |
~MSXMidi() override; |
| 19 |
|
| 20 |
void reset(EmuTime time) override; |
| 21 |
[[nodiscard]] uint8_t readIO(uint16_t port, EmuTime time) override; |
| 22 |
[[nodiscard]] uint8_t peekIO(uint16_t port, EmuTime time) const override; |
| 23 |
void writeIO(uint16_t port, uint8_t value, EmuTime time) override; |
| 24 |
|
| 25 |
|
| 26 |
[[nodiscard]] bool ready() override; |
| 27 |
[[nodiscard]] bool acceptsData() override; |
| 28 |
void setDataBits(DataBits bits) override; |
| 29 |
void setStopBits(StopBits bits) override; |
| 30 |
void setParityBit(bool enable, Parity parity) override; |
| 31 |
void recvByte(uint8_t value, EmuTime time) override; |
| 32 |
|
| 33 |
template<typename Archive> |
| 34 |
void serialize(Archive& ar, unsigned version); |
| 35 |
|
| 36 |
private: |
| 37 |
void setTimerIRQ(bool status, EmuTime time); |
| 38 |
void enableTimerIRQ(bool enabled, EmuTime time); |
| 39 |
void updateEdgeEvents(EmuTime time); |
| 40 |
void setRxRDYIRQ(bool status); |
| 41 |
void enableRxRDYIRQ(bool enabled); |
| 42 |
|
| 43 |
void registerIOports(uint8_t value); |
| 44 |
|
| 45 |
private: |
| 46 |
struct Counter0 final : ClockPinListener { |
| 47 |
void signal(ClockPin& pin, EmuTime time) override; |
| 48 |
void signalPosEdge(ClockPin& pin, EmuTime time) override; |
| 49 |
} cntr0; |
| 50 |
|
| 51 |
struct Counter2 final : ClockPinListener { |
| 52 |
void signal(ClockPin& pin, EmuTime time) override; |
| 53 |
void signalPosEdge(ClockPin& pin, EmuTime time) override; |
| 54 |
} cntr2; |
| 55 |
|
| 56 |
struct Interface final : I8251Interface { |
| 57 |
void setRxRDY(bool status, EmuTime time) override; |
| 58 |
void setDTR(bool status, EmuTime time) override; |
| 59 |
void setRTS(bool status, EmuTime time) override; |
| 60 |
[[nodiscard]] bool getDSR(EmuTime time) override; |
| 61 |
[[nodiscard]] bool getCTS(EmuTime time) override; |
| 62 |
void setDataBits(DataBits bits) override; |
| 63 |
void setStopBits(StopBits bits) override; |
| 64 |
void setParityBit(bool enable, Parity parity) override; |
| 65 |
void recvByte(uint8_t value, EmuTime time) override; |
| 66 |
void signal(EmuTime time) override; |
| 67 |
} interface; |
| 68 |
|
| 69 |
IRQHelper timerIRQ; |
| 70 |
IRQHelper rxrdyIRQ; |
| 71 |
bool timerIRQlatch = false; |
| 72 |
bool timerIRQenabled = false; |
| 73 |
bool rxrdyIRQlatch = false; |
| 74 |
bool rxrdyIRQenabled = false; |
| 75 |
|
| 76 |
const bool isExternalMSXMIDI; |
| 77 |
bool isEnabled; |
| 78 |
bool isLimitedTo8251 = true; |
| 79 |
|
| 80 |
|
| 81 |
MidiOutConnector outConnector; |
| 82 |
I8251 i8251; |
| 83 |
I8254 i8254; |
| 84 |
}; |
| 85 |
SERIALIZE_CLASS_VERSION(MSXMidi, 2); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
#endif |