OXYGENHUB
◆ main openmsx / src / MSXTurboRPause.cc
2.0 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "MSXTurboRPause.hh"
2
3
#include "LedStatus.hh"
4
#include "MSXMotherBoard.hh"
5
#include "serialize.hh"
6
7
namespace openmsx {
8
9
MSXTurboRPause::MSXTurboRPause(const DeviceConfig& config)
10
	: MSXDevice(config)
11
	, pauseSetting(
12
		getCommandController(), "turborpause",
13
		"status of the TurboR pause", false)
14
{
15
	pauseSetting.attach(*this);
16
	reset(EmuTime::dummy());
17
}
18
19
MSXTurboRPause::~MSXTurboRPause()
20
{
21
	powerDown(EmuTime::dummy());
22
	pauseSetting.detach(*this);
23
}
24
25
void MSXTurboRPause::powerDown(EmuTime time)
26
{
27
	writeIO(0, 0, time); // send LED OFF events (if needed)
28
}
29
30
void MSXTurboRPause::reset(EmuTime time)
31
{
32
	pauseSetting.setBoolean(false);
33
	writeIO(0, 0, time);
34
}
35
36
byte MSXTurboRPause::readIO(uint16_t port, EmuTime time)
37
{
38
	return peekIO(port, time);
39
}
40
41
byte MSXTurboRPause::peekIO(uint16_t /*port*/, EmuTime /*time*/) const
42
{
43
	return pauseSetting.getBoolean() ? 1 : 0;
44
}
45
46
void MSXTurboRPause::writeIO(uint16_t /*port*/, byte value, EmuTime /*time*/)
47
{
48
	status = value;
49
	if (bool newTurboLed = (status & 0x80) != 0;
50
	    newTurboLed != turboLed) {
51
		turboLed = newTurboLed;
52
		getLedStatus().setLed(LedStatus::TURBO, turboLed);
53
	}
54
	updatePause();
55
}
56
57
void MSXTurboRPause::update(const Setting& /*setting*/) noexcept
58
{
59
	updatePause();
60
}
61
62
void MSXTurboRPause::updatePause()
63
{
64
	if (bool newHwPause = (status & 0x02) && pauseSetting.getBoolean();
65
	    newHwPause != hwPause) {
66
		hwPause = newHwPause;
67
		if (hwPause) {
68
			getMotherBoard().pause();
69
		} else {
70
			getMotherBoard().unpause();
71
		}
72
	}
73
74
	bool newPauseLed = (status & 0x01) || hwPause;
75
	if (newPauseLed != pauseLed) {
76
		pauseLed = newPauseLed;
77
		getLedStatus().setLed(LedStatus::PAUSE, pauseLed);
78
	}
79
}
80
81
template<typename Archive>
82
void MSXTurboRPause::serialize(Archive& ar, unsigned /*version*/)
83
{
84
	ar.template serializeBase<MSXDevice>(*this);
85
	ar.serialize("status", status);
86
	if constexpr (Archive::IS_LOADER) {
87
		writeIO(0, status, EmuTime::dummy());
88
	}
89
}
90
INSTANTIATE_SERIALIZE_METHODS(MSXTurboRPause);
91
REGISTER_MSXDEVICE(MSXTurboRPause, "TurboRPause");
92
93
} // namespace openmsx