RP5C01.hh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This class implements the RP5C01 chip (RTC)
  2. //
  3. // * For techncal details on RP5C01 see
  4. // http://w3.qahwah.net/joost/openMSX/RP5C01.pdf
  5. #ifndef RP5C01_HH
  6. #define RP5C01_HH
  7. #include "Clock.hh"
  8. #include "EnumSetting.hh"
  9. #include "openmsx.hh"
  10. #include <string>
  11. namespace openmsx {
  12. class CommandController;
  13. class SRAM;
  14. class RP5C01
  15. {
  16. public:
  17. enum RTCMode { EMUTIME, REALTIME };
  18. RP5C01(CommandController& commandController, SRAM& regs,
  19. EmuTime::param time, const std::string& name);
  20. void reset(EmuTime::param time);
  21. nibble readPort(nibble port, EmuTime::param time);
  22. nibble peekPort(nibble port) const;
  23. void writePort(nibble port, nibble value, EmuTime::param time);
  24. template<typename Archive>
  25. void serialize(Archive& ar, unsigned version);
  26. private:
  27. void initializeTime();
  28. void updateTimeRegs(EmuTime::param time);
  29. void regs2Time();
  30. void time2Regs();
  31. void resetAlarm();
  32. static constexpr unsigned FREQ = 16384;
  33. SRAM& regs;
  34. EnumSetting<RTCMode> modeSetting;
  35. Clock<FREQ> reference;
  36. unsigned fraction;
  37. unsigned seconds, minutes, hours;
  38. unsigned dayWeek, years, leapYear;
  39. int days, months; // these two can be -1
  40. nibble modeReg, testReg, resetReg;
  41. };
  42. } // namespace openmsx
  43. #endif