openMSX
MSXTurboRPause.cc
Go to the documentation of this file.
1#include "MSXTurboRPause.hh"
2#include "LedStatus.hh"
3#include "MSXMotherBoard.hh"
4#include "serialize.hh"
5
6namespace openmsx {
7
9 : MSXDevice(config)
10 , pauseSetting(
11 getCommandController(), "turborpause",
12 "status of the TurboR pause", false)
13{
14 pauseSetting.attach(*this);
15 reset(EmuTime::dummy());
16}
17
19{
20 powerDown(EmuTime::dummy());
21 pauseSetting.detach(*this);
22}
23
24void MSXTurboRPause::powerDown(EmuTime::param time)
25{
26 writeIO(0, 0, time); // send LED OFF events (if needed)
27}
28
29void MSXTurboRPause::reset(EmuTime::param time)
30{
31 pauseSetting.setBoolean(false);
32 writeIO(0, 0, time);
33}
34
35byte MSXTurboRPause::readIO(word port, EmuTime::param time)
36{
37 return peekIO(port, time);
38}
39
40byte MSXTurboRPause::peekIO(word /*port*/, EmuTime::param /*time*/) const
41{
42 return pauseSetting.getBoolean() ? 1 : 0;
43}
44
45void MSXTurboRPause::writeIO(word /*port*/, byte value, EmuTime::param /*time*/)
46{
47 status = value;
48 if (bool newTurboLed = (status & 0x80) != 0;
49 newTurboLed != turboLed) {
50 turboLed = newTurboLed;
52 }
53 updatePause();
54}
55
56void MSXTurboRPause::update(const Setting& /*setting*/) noexcept
57{
58 updatePause();
59}
60
61void MSXTurboRPause::updatePause()
62{
63 if (bool newHwPause = (status & 0x02) && pauseSetting.getBoolean();
64 newHwPause != hwPause) {
65 hwPause = newHwPause;
66 if (hwPause) {
68 } else {
70 }
71 }
72
73 bool newPauseLed = (status & 0x01) || hwPause;
74 if (newPauseLed != pauseLed) {
75 pauseLed = newPauseLed;
77 }
78}
79
80template<typename Archive>
81void MSXTurboRPause::serialize(Archive& ar, unsigned /*version*/)
82{
83 ar.template serializeBase<MSXDevice>(*this);
84 ar.serialize("status", status);
85 if constexpr (Archive::IS_LOADER) {
86 writeIO(0, status, EmuTime::dummy());
87 }
88}
91
92} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
bool getBoolean() const noexcept
void setLed(Led led, bool status)
Definition LedStatus.cc:44
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition MSXDevice.cc:70
LedStatus & getLedStatus() const
Definition MSXDevice.cc:153
void pause()
Pause MSX machine.
This class implements the MSX Turbo-R pause key.
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
MSXTurboRPause(const DeviceConfig &config)
void powerDown(EmuTime::param time) override
This method is called when MSX is powered down.
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
void reset(EmuTime::param time) override
This method is called on reset.
void serialize(Archive &ar, unsigned version)
void detach(Observer< T > &observer)
Definition Subject.hh:60
void attach(Observer< T > &observer)
Definition Subject.hh:54
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)