OXYGENHUB
◆ main openmsx / src / RP5C01.hh
1.2 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
// This class implements the RP5C01 chip (RTC)
2
//
3
// * For technical details on RP5C01 see
4
//     http://w3.qahwah.net/joost/openMSX/RP5C01.pdf
5
6
#ifndef RP5C01_HH
7
#define RP5C01_HH
8
9
#include "Clock.hh"
10
#include "EnumSetting.hh"
11
12
#include <cstdint>
13
#include <string>
14
15
namespace openmsx {
16
17
using uint4_t = uint8_t;
18
19
class CommandController;
20
class SRAM;
21
22
class RP5C01
23
{
24
public:
25
	enum class RTCMode : uint8_t { EMUTIME, REALTIME };
26
27
	RP5C01(CommandController& commandController, SRAM& regs,
28
	       EmuTime time, const std::string& name);
29
30
	void reset(EmuTime time);
31
	[[nodiscard]] uint4_t readPort(uint4_t port, EmuTime time);
32
	[[nodiscard]] uint4_t peekPort(uint4_t port) const;
33
	void writePort(uint4_t port, uint4_t value, EmuTime time);
34
35
	template<typename Archive>
36
	void serialize(Archive& ar, unsigned version);
37
38
private:
39
	void initializeTime();
40
	void updateTimeRegs(EmuTime time);
41
	void regs2Time();
42
	void time2Regs();
43
	void resetAlarm();
44
45
private:
46
	static constexpr unsigned FREQ = 16384;
47
48
	SRAM& regs;
49
	EnumSetting<RTCMode> modeSetting;
50
51
	Clock<FREQ> reference;
52
	unsigned fraction;
53
	unsigned seconds, minutes, hours;
54
	unsigned dayWeek, years, leapYear;
55
	int days, months; // these two can be -1
56
57
	uint4_t modeReg, testReg, resetReg;
58
};
59
60
} // namespace openmsx
61
62
#endif