MSXRTC.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "MSXRTC.hh"
  2. #include "serialize.hh"
  3. #include "unreachable.hh"
  4. namespace openmsx {
  5. MSXRTC::MSXRTC(const DeviceConfig& config)
  6. : MSXDevice(config)
  7. , sram(getName() + " SRAM", 4 * 13, config)
  8. , rp5c01(getCommandController(), sram, getCurrentTime(), getName())
  9. {
  10. reset(getCurrentTime());
  11. }
  12. void MSXRTC::reset(EmuTime::param time)
  13. {
  14. // TODO verify on real hardware .. how?
  15. // - registerLatch set to zero or some other value?
  16. // - only on power-up or also on reset?
  17. registerLatch = 0;
  18. rp5c01.reset(time);
  19. }
  20. byte MSXRTC::readIO(word /*port*/, EmuTime::param time)
  21. {
  22. return rp5c01.readPort(registerLatch, time) | 0xF0;
  23. }
  24. byte MSXRTC::peekIO(word /*port*/, EmuTime::param /*time*/) const
  25. {
  26. return rp5c01.peekPort(registerLatch) | 0xF0;
  27. }
  28. void MSXRTC::writeIO(word port, byte value, EmuTime::param time)
  29. {
  30. switch (port & 0x01) {
  31. case 0:
  32. registerLatch = value & 0x0F;
  33. break;
  34. case 1:
  35. rp5c01.writePort(registerLatch, value & 0x0F, time);
  36. break;
  37. default:
  38. UNREACHABLE;
  39. }
  40. }
  41. template<typename Archive>
  42. void MSXRTC::serialize(Archive& ar, unsigned /*version*/)
  43. {
  44. ar.template serializeBase<MSXDevice>(*this);
  45. ar.serialize("sram", sram,
  46. "rp5c01", rp5c01,
  47. "registerLatch", registerLatch);
  48. }
  49. INSTANTIATE_SERIALIZE_METHODS(MSXRTC);
  50. REGISTER_MSXDEVICE(MSXRTC, "RTC");
  51. } // namespace openmsx