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 : 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  byte readStatus(EmuTime::param time);
25  byte readData(EmuTime::param time);
26  byte peekStatus(EmuTime::param time) const;
27  byte peekData(EmuTime::param time) const;
28 
29  bool pendingIRQ() const;
30 
31  template<typename Archive>
32  void serialize(Archive& ar, unsigned version);
33 
34 private:
35  // MidiInConnector
36  bool ready() override;
37  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 : 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 : 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
byte readData(EmuTime::param time)
Definition: YM2148.cc:124
void reset()
Definition: YM2148.cc:43
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
bool pendingIRQ() const
Definition: YM2148.cc:222
byte readStatus(EmuTime::param time)
Definition: YM2148.cc:114
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:31
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
byte peekData(EmuTime::param time) const
Definition: YM2148.cc:130
void serialize(Archive &ar, unsigned version)
Definition: YM2148.cc:228
YM2148(const std::string &name, MSXMotherBoard &motherBoard)
Definition: YM2148.cc:31
void writeData(byte value, EmuTime::param time)
Definition: YM2148.cc:179
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void writeCommand(byte value)
Definition: YM2148.cc:136
byte peekStatus(EmuTime::param time) const
Definition: YM2148.cc:118
#define OUTER(type, member)
Definition: outer.hh:38