OXYGENHUB
◆ main openmsx / src / serial / YM2148.hh
2.0 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
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 "outer.hh"
9
10
#include <cstdint>
11
12
namespace openmsx {
13
14
class MSXMotherBoard;
15
class Scheduler;
16
17
class YM2148 final : public MidiInConnector
18
{
19
public:
20
	YM2148(const std::string& name, MSXMotherBoard& motherBoard);
21
	void reset();
22
23
	void writeCommand(uint8_t value);
24
	void writeData(uint8_t value, EmuTime time);
25
	[[nodiscard]] uint8_t readStatus(EmuTime time) const;
26
	[[nodiscard]] uint8_t readData(EmuTime time);
27
	[[nodiscard]] uint8_t peekStatus(EmuTime time) const;
28
	[[nodiscard]] uint8_t peekData(EmuTime time) const;
29
30
	[[nodiscard]] bool pendingIRQ() const;
31
32
	template<typename Archive>
33
	void serialize(Archive& ar, unsigned version);
34
35
private:
36
	// MidiInConnector
37
	[[nodiscard]] bool ready() override;
38
	[[nodiscard]] bool acceptsData() override;
39
	void setDataBits(DataBits bits) override;
40
	void setStopBits(StopBits bits) override;
41
	void setParityBit(bool enable, Parity parity) override;
42
	void recvByte(uint8_t value, EmuTime time) override;
43
44
	// Schedulable
45
	struct SyncRecv final : Schedulable {
46
		friend class YM2148;
47
		explicit SyncRecv(Scheduler& s) : Schedulable(s) {}
48
		void executeUntil(EmuTime time) override {
49
			auto& ym2148 = OUTER(YM2148, syncRecv);
50
			ym2148.execRecv(time);
51
		}
52
	} syncRecv;
53
	struct SyncTrans final : Schedulable {
54
		friend class YM2148;
55
		explicit SyncTrans(Scheduler& s) : Schedulable(s) {}
56
		void executeUntil(EmuTime time) override {
57
			auto& ym2148 = OUTER(YM2148, syncTrans);
58
			ym2148.execTrans(time);
59
		}
60
	} syncTrans;
61
	void execRecv (EmuTime time);
62
	void execTrans(EmuTime time);
63
64
	void send(uint8_t value, EmuTime time);
65
66
	IRQHelper rxIRQ;
67
	IRQHelper txIRQ;
68
	bool rxReady;
69
	uint8_t rxBuffer;      //<! Byte received from MIDI in connector.
70
	uint8_t txBuffer1 = 0; //<! The byte currently being send.
71
	uint8_t txBuffer2 = 0; //<! The next to-be-send byte.
72
	uint8_t status;
73
	uint8_t commandReg;
74
75
	MidiOutConnector outConnector;
76
};
77
SERIALIZE_CLASS_VERSION(YM2148, 2);
78
79
} // namespace openmsx
80
81
#endif