| 1 |
#include "MSXRTC.hh" |
| 2 |
|
| 3 |
#include "serialize.hh" |
| 4 |
|
| 5 |
#include "unreachable.hh" |
| 6 |
|
| 7 |
namespace openmsx { |
| 8 |
|
| 9 |
MSXRTC::MSXRTC(const DeviceConfig& config) |
| 10 |
: MSXDevice(config) |
| 11 |
, sram(getName() + " SRAM", 4 * 13, config) |
| 12 |
, rp5c01(getCommandController(), sram, getCurrentTime(), getName()) |
| 13 |
{ |
| 14 |
reset(getCurrentTime()); |
| 15 |
} |
| 16 |
|
| 17 |
void MSXRTC::reset(EmuTime time) |
| 18 |
{ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
registerLatch = 0; |
| 23 |
rp5c01.reset(time); |
| 24 |
} |
| 25 |
|
| 26 |
uint8_t MSXRTC::readIO(uint16_t port, EmuTime time) |
| 27 |
{ |
| 28 |
return port & 0x01 ? rp5c01.readPort(registerLatch, time) | 0xF0 : 0xFF; |
| 29 |
} |
| 30 |
|
| 31 |
uint8_t MSXRTC::peekIO(uint16_t port, EmuTime ) const |
| 32 |
{ |
| 33 |
return port & 0x01 ? rp5c01.peekPort(registerLatch) | 0xF0 : 0xFF; |
| 34 |
} |
| 35 |
|
| 36 |
void MSXRTC::writeIO(uint16_t port, uint8_t value, EmuTime time) |
| 37 |
{ |
| 38 |
switch (port & 0x01) { |
| 39 |
case 0: |
| 40 |
registerLatch = value & 0x0F; |
| 41 |
break; |
| 42 |
case 1: |
| 43 |
rp5c01.writePort(registerLatch, value & 0x0F, time); |
| 44 |
break; |
| 45 |
default: |
| 46 |
UNREACHABLE; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
template<typename Archive> |
| 51 |
void MSXRTC::serialize(Archive& ar, unsigned ) |
| 52 |
{ |
| 53 |
ar.template serializeBase<MSXDevice>(*this); |
| 54 |
ar.serialize("sram", sram, |
| 55 |
"rp5c01", rp5c01, |
| 56 |
"registerLatch", registerLatch); |
| 57 |
} |
| 58 |
INSTANTIATE_SERIALIZE_METHODS(MSXRTC); |
| 59 |
REGISTER_MSXDEVICE(MSXRTC, "RTC"); |
| 60 |
|
| 61 |
} |