OXYGENHUB
◆ main openmsx / src / serial / MSXRS232.hh
3.1 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef MSXRS232_HH
2
#define MSXRS232_HH
3
4
#include "I8251.hh"
5
#include "I8254.hh"
6
#include "IRQHelper.hh"
7
#include "MSXDevice.hh"
8
#include "RS232Connector.hh"
9
10
#include <memory>
11
12
namespace openmsx {
13
14
class Ram;
15
class Rom;
16
class BooleanSetting;
17
18
class MSXRS232 final : public MSXDevice, public RS232Connector
19
{
20
public:
21
	explicit MSXRS232(DeviceConfig& config);
22
	~MSXRS232() override;
23
24
	void powerUp(EmuTime time) override;
25
	void reset(EmuTime time) override;
26
	[[nodiscard]] uint8_t readIO(uint16_t port, EmuTime time) override;
27
	[[nodiscard]] uint8_t peekIO(uint16_t port, EmuTime time) const override;
28
	void writeIO(uint16_t port, uint8_t value, EmuTime time) override;
29
	[[nodiscard]] uint8_t readMem(uint16_t address, EmuTime time) override;
30
	// TODO: implement peekMem, because the default isn't OK anymore
31
	[[nodiscard]] const uint8_t *getReadCacheLine(uint16_t start) const override;
32
	void writeMem(uint16_t address, uint8_t value, EmuTime time) override;
33
	[[nodiscard]] uint8_t* getWriteCacheLine(uint16_t start) override;
34
	[[nodiscard]] bool allowUnaligned() const override;
35
36
	// RS232Connector  (input)
37
	void setDataBits(DataBits bits) override;
38
	void setStopBits(StopBits bits) override;
39
	void setParityBit(bool enable, Parity parity) override;
40
	void recvByte(uint8_t value, EmuTime time) override;
41
	[[nodiscard]] bool ready() override;
42
	[[nodiscard]] bool acceptsData() override;
43
44
	template<typename Archive>
45
	void serialize(Archive& ar, unsigned version);
46
47
private:
48
	[[nodiscard]] uint8_t readIOImpl(uint16_t port, EmuTime time);
49
	void writeIOImpl(uint16_t port, uint8_t value, EmuTime time);
50
	void notifyBaudRate();
51
52
	[[nodiscard]] uint8_t readStatus(EmuTime time);
53
	void setIRQMask(uint8_t value);
54
	void setRxRDYIRQ(bool status);
55
	void enableRxRDYIRQ(bool enabled);
56
57
	struct Counter0 final : ClockPinListener {
58
		void signal(ClockPin& pin, EmuTime time) override;
59
		void signalPosEdge(ClockPin& pin, EmuTime time) override;
60
	} cntr0; // counter 0 rx clock pin
61
62
	struct Counter1 final : ClockPinListener {
63
		void signal(ClockPin& pin, EmuTime time) override;
64
		void signalPosEdge(ClockPin& pin, EmuTime time) override;
65
	} cntr1; // counter 1 tx clock pin
66
67
	I8254 i8254;
68
69
	struct Interface final : I8251Interface {
70
		void setRxRDY(bool status, EmuTime time) override;
71
		void setDTR(bool status, EmuTime time) override;
72
		void setRTS(bool status, EmuTime time) override;
73
		[[nodiscard]] bool getDSR(EmuTime time) override;
74
		[[nodiscard]] bool getCTS(EmuTime time) override;
75
		void setDataBits(DataBits bits) override;
76
		void setStopBits(StopBits bits) override;
77
		void setParityBit(bool enable, Parity parity) override;
78
		void recvByte(uint8_t value, EmuTime time) override;
79
		void signal(EmuTime time) override;
80
	} interface;
81
82
	I8251 i8251;
83
	const std::unique_ptr<Rom> rom; // can be nullptr
84
	const std::unique_ptr<Ram> ram; // can be nullptr
85
86
	IRQHelper rxrdyIRQ;
87
	bool rxrdyIRQlatch = false;
88
	bool rxrdyIRQenabled = false;
89
90
	const bool hasMemoryBasedIo;
91
	const bool hasRIPin;
92
	const bool inputsPullup;
93
	bool ioAccessEnabled;
94
95
	const std::unique_ptr<BooleanSetting> switchSetting; // can be nullptr
96
};
97
SERIALIZE_CLASS_VERSION(MSXRS232, 2);
98
99
100
} // namespace openmsx
101
102
#endif