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 
6 namespace openmsx {
7 
9  : MSXDevice(config)
10  , pauseSetting(
11  getCommandController(), "turborpause",
12  "status of the TurboR pause", false)
13  , status(255)
14  , pauseLed(false)
15  , turboLed(false)
16  , hwPause(false)
17 {
18  pauseSetting.attach(*this);
19  reset(EmuTime::dummy());
20 }
21 
23 {
24  powerDown(EmuTime::dummy());
25  pauseSetting.detach(*this);
26 }
27 
28 void MSXTurboRPause::powerDown(EmuTime::param time)
29 {
30  writeIO(0, 0, time); // send LED OFF events (if needed)
31 }
32 
33 void MSXTurboRPause::reset(EmuTime::param time)
34 {
35  pauseSetting.setBoolean(false);
36  writeIO(0, 0, time);
37 }
38 
39 byte MSXTurboRPause::readIO(word port, EmuTime::param time)
40 {
41  return peekIO(port, time);
42 }
43 
44 byte MSXTurboRPause::peekIO(word /*port*/, EmuTime::param /*time*/) const
45 {
46  return pauseSetting.getBoolean() ? 1 : 0;
47 }
48 
49 void MSXTurboRPause::writeIO(word /*port*/, byte value, EmuTime::param /*time*/)
50 {
51  status = value;
52  bool newTurboLed = (status & 0x80) != 0;
53  if (newTurboLed != turboLed) {
54  turboLed = newTurboLed;
56  }
57  updatePause();
58 }
59 
60 void MSXTurboRPause::update(const Setting& /*setting*/)
61 {
62  updatePause();
63 }
64 
65 void MSXTurboRPause::updatePause()
66 {
67  bool newHwPause = (status & 0x02) && pauseSetting.getBoolean();
68  if (newHwPause != hwPause) {
69  hwPause = newHwPause;
70  if (hwPause) {
72  } else {
74  }
75  }
76 
77  bool newPauseLed = (status & 0x01) || hwPause;
78  if (newPauseLed != pauseLed) {
79  pauseLed = newPauseLed;
81  }
82 }
83 
84 template<typename Archive>
85 void MSXTurboRPause::serialize(Archive& ar, unsigned /*version*/)
86 {
87  ar.template serializeBase<MSXDevice>(*this);
88  ar.serialize("status", status);
89  if (ar.isLoader()) {
90  writeIO(0, status, EmuTime::dummy());
91  }
92 }
94 REGISTER_MSXDEVICE(MSXTurboRPause, "TurboRPause");
95 
96 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:31
openmsx::MSXTurboRPause::~MSXTurboRPause
~MSXTurboRPause() override
Definition: MSXTurboRPause.cc:22
openmsx::Subject::detach
void detach(Observer< T > &observer)
Definition: Subject.hh:56
openmsx::MSXTurboRPause::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXTurboRPause.cc:33
serialize.hh
openmsx::MSXTurboRPause::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MSXTurboRPause.cc:39
openmsx::DeviceConfig
Definition: DeviceConfig.hh:19
openmsx::MSXTurboRPause::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXTurboRPause.cc:44
openmsx::Subject::attach
void attach(Observer< T > &observer)
Definition: Subject.hh:50
MSXTurboRPause.hh
openmsx::Setting
Definition: Setting.hh:119
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXTurboRPause::powerDown
void powerDown(EmuTime::param time) override
This method is called when MSX is powered down.
Definition: MSXTurboRPause.cc:28
LedStatus.hh
openmsx::MSXMotherBoard::unpause
void unpause()
Definition: MSXMotherBoard.cc:533
openmsx::LedStatus::PAUSE
Definition: LedStatus.hh:23
openmsx::MSXTurboRPause
This class implements the MSX Turbo-R pause key.
Definition: MSXTurboRPause.hh:25
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::MSXDevice::getMotherBoard
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:74
openmsx::MSXDevice::getLedStatus
LedStatus & getLedStatus() const
Definition: MSXDevice.cc:158
openmsx::MSXTurboRPause::MSXTurboRPause
MSXTurboRPause(const DeviceConfig &config)
Definition: MSXTurboRPause.cc:8
openmsx::MSXTurboRPause::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXTurboRPause.cc:85
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXTurboRPause::writeIO
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.
Definition: MSXTurboRPause.cc:49
openmsx::LedStatus::setLed
void setLed(Led led, bool status)
Definition: LedStatus.cc:39
openmsx::BooleanSetting::setBoolean
void setBoolean(bool b)
Definition: BooleanSetting.hh:18
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
MSXMotherBoard.hh
openmsx::BooleanSetting::getBoolean
bool getBoolean() const noexcept
Definition: BooleanSetting.hh:17
openmsx::LedStatus::TURBO
Definition: LedStatus.hh:24
openmsx::MSXMotherBoard::pause
void pause()
Pause MSX machine.
Definition: MSXMotherBoard.cc:525