openMSX
MSXRTC.cc
Go to the documentation of this file.
1 #include "MSXRTC.hh"
2 #include "serialize.hh"
3 #include "unreachable.hh"
4 
5 namespace openmsx {
6 
8  : MSXDevice(config)
9  , sram(getName() + " SRAM", 4 * 13, config)
10  , rp5c01(getCommandController(), sram, getCurrentTime(), getName())
11 {
13 }
14 
15 void MSXRTC::reset(EmuTime::param time)
16 {
17  // TODO verify on real hardware .. how?
18  // - registerLatch set to zero or some other value?
19  // - only on power-up or also on reset?
20  registerLatch = 0;
21  rp5c01.reset(time);
22 }
23 
24 byte MSXRTC::readIO(word /*port*/, EmuTime::param time)
25 {
26  return rp5c01.readPort(registerLatch, time) | 0xF0;
27 }
28 
29 byte MSXRTC::peekIO(word /*port*/, EmuTime::param /*time*/) const
30 {
31  return rp5c01.peekPort(registerLatch) | 0xF0;
32 }
33 
34 void MSXRTC::writeIO(word port, byte value, EmuTime::param time)
35 {
36  switch (port & 0x01) {
37  case 0:
38  registerLatch = value & 0x0F;
39  break;
40  case 1:
41  rp5c01.writePort(registerLatch, value & 0x0F, time);
42  break;
43  default:
45  }
46 }
47 
48 template<typename Archive>
49 void MSXRTC::serialize(Archive& ar, unsigned /*version*/)
50 {
51  ar.template serializeBase<MSXDevice>(*this);
52  ar.serialize("sram", sram,
53  "rp5c01", rp5c01,
54  "registerLatch", registerLatch);
55 }
58 
59 } // namespace openmsx
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXRTC.cc:15
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
MSXRTC(const DeviceConfig &config)
Definition: MSXRTC.cc:7
void serialize(Archive &ar, unsigned version)
Definition: MSXRTC.cc:49
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
nibble peekPort(nibble port) const
Definition: RP5C01.cc:82
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXRTC.cc:29
void writePort(nibble port, nibble value, EmuTime::param time)
Definition: RP5C01.cc:99
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:129
void reset(EmuTime::param time)
Definition: RP5C01.cc:57
nibble readPort(nibble port, EmuTime::param time)
Definition: RP5C01.cc:65
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
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: MSXRTC.cc:34
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: MSXRTC.cc:24
#define UNREACHABLE
Definition: unreachable.hh:38