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
void serialize(Archive &ar, unsigned version)
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
MSXTurboRPause(const DeviceConfig &config)
void pause()
Pause MSX machine.
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.
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
void attach(Observer< T > &observer)
Definition: Subject.hh:45
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.
LedStatus & getLedStatus() const
Definition: MSXDevice.cc:161
void reset(EmuTime::param time) override
This method is called on reset.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:77
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
void powerDown(EmuTime::param time) override
This method is called when MSX is powered down.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:840
void detach(Observer< T > &observer)
Definition: Subject.hh:51
void setLed(Led led, bool status)
Definition: LedStatus.cc:39
This class implements the MSX Turbo-R pause key.