openMSX
YM2148.hh
Go to the documentation of this file.
1 #ifndef YM2148_HH
2 #define YM2148_HH
3 
4 #include "IRQHelper.hh"
5 #include "MidiInConnector.hh"
6 #include "MidiOutConnector.hh"
7 #include "Schedulable.hh"
8 #include "openmsx.hh"
9 #include "outer.hh"
10 
11 namespace openmsx {
12 
13 class MSXMotherBoard;
14 class Scheduler;
15 
16 class YM2148 final : public MidiInConnector
17 {
18 public:
19  YM2148(const std::string& name, MSXMotherBoard& motherBoard);
20  void reset();
21 
22  void writeCommand(byte value);
23  void writeData(byte value, EmuTime::param time);
24  [[nodiscard]] byte readStatus(EmuTime::param time) const;
25  [[nodiscard]] byte readData(EmuTime::param time);
26  [[nodiscard]] byte peekStatus(EmuTime::param time) const;
27  [[nodiscard]] byte peekData(EmuTime::param time) const;
28 
29  [[nodiscard]] bool pendingIRQ() const;
30 
31  template<typename Archive>
32  void serialize(Archive& ar, unsigned version);
33 
34 private:
35  // MidiInConnector
36  [[nodiscard]] bool ready() override;
37  [[nodiscard]] bool acceptsData() override;
38  void setDataBits(DataBits bits) override;
39  void setStopBits(StopBits bits) override;
40  void setParityBit(bool enable, ParityBit parity) override;
41  void recvByte(byte value, EmuTime::param time) override;
42 
43  // Schedulable
44  struct SyncRecv final : Schedulable {
45  friend class YM2148;
46  explicit SyncRecv(Scheduler& s) : Schedulable(s) {}
47  void executeUntil(EmuTime::param time) override {
48  auto& ym2148 = OUTER(YM2148, syncRecv);
49  ym2148.execRecv(time);
50  }
51  } syncRecv;
52  struct SyncTrans final : Schedulable {
53  friend class YM2148;
54  explicit SyncTrans(Scheduler& s) : Schedulable(s) {}
55  void executeUntil(EmuTime::param time) override {
56  auto& ym2148 = OUTER(YM2148, syncTrans);
57  ym2148.execTrans(time);
58  }
59  } syncTrans;
60  void execRecv (EmuTime::param time);
61  void execTrans(EmuTime::param time);
62 
63  void send(byte value, EmuTime::param time);
64 
65  IRQHelper rxIRQ;
66  IRQHelper txIRQ;
67  bool rxReady;
68  byte rxBuffer; //<! Byte received from MIDI in connector.
69  byte txBuffer1; //<! The byte currently being send.
70  byte txBuffer2; //<! The next to-be-send byte.
71  byte status;
72  byte commandReg;
73 
74  MidiOutConnector outConnector;
75 };
77 
78 } // namespace openmsx
79 
80 #endif
openmsx.hh
openmsx::MidiInConnector
Definition: MidiInConnector.hh:13
openmsx::Scheduler
Definition: Scheduler.hh:34
openmsx::YM2148::writeCommand
void writeCommand(byte value)
Definition: YM2148.cc:136
openmsx::YM2148::pendingIRQ
bool pendingIRQ() const
Definition: YM2148.cc:222
openmsx::YM2148::reset
void reset()
Definition: YM2148.cc:43
openmsx::YM2148::YM2148
YM2148(const std::string &name, MSXMotherBoard &motherBoard)
Definition: YM2148.cc:31
openmsx::YM2148::peekStatus
byte peekStatus(EmuTime::param time) const
Definition: YM2148.cc:118
openmsx::Schedulable
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:34
openmsx::IntHelper< IRQSource >
Schedulable.hh
openmsx::YM2148::readStatus
byte readStatus(EmuTime::param time) const
Definition: YM2148.cc:114
openmsx::YM2148
Definition: YM2148.hh:17
openmsx::YM2148::readData
byte readData(EmuTime::param time)
Definition: YM2148.cc:124
openmsx::YM2148::serialize
void serialize(Archive &ar, unsigned version)
Definition: YM2148.cc:228
openmsx::SERIALIZE_CLASS_VERSION
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
openmsx::MidiOutConnector
Definition: MidiOutConnector.hh:12
OUTER
#define OUTER(type, member)
Definition: outer.hh:41
MidiInConnector.hh
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:61
openmsx::SerialDataInterface::StopBits
StopBits
Definition: SerialDataInterface.hh:15
openmsx::SerialDataInterface::DataBits
DataBits
Definition: SerialDataInterface.hh:12
outer.hh
openmsx::Schedulable
Schedulable
Definition: Schedulable.cc:69
MidiOutConnector.hh
openmsx::YM2148::peekData
byte peekData(EmuTime::param time) const
Definition: YM2148.cc:130
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:132
openmsx::YM2148::writeData
void writeData(byte value, EmuTime::param time)
Definition: YM2148.cc:179
openmsx::SerialDataInterface::ParityBit
ParityBit
Definition: SerialDataInterface.hh:19
IRQHelper.hh
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5