Skip to content

RTC DS3231 Design

Przemyslaw Rachwlal edited this page May 4, 2026 · 1 revision

RTC DS3231 Design

Overview

The RtcDevice emulates a DS3231 real-time clock connected via the system bus as a memory-mapped device.

Device Interface

  • Base address: Configurable (default 0xFF20)
  • Address range: 0xFF20–0xFF2F (16 registers)
  • Type: IClockedDevice + IBusDevice

Register Map

Offset Register Access Description
0x00 Seconds R/W 0–59 (BCD)
0x01 Minutes R/W 0–59 (BCD)
0x02 Hours R/W 0–23 (BCD, 24h mode)
0x03 Day R/W 1–7
0x04 Date R/W 1–31 (BCD)
0x05 Month/Century R/W 1–12 + century bit (BCD)
0x06 Year R/W 0–99 (BCD)
0x07–0x0E Alarm/Control/Status R/W Per DS3231 spec
0x0F Temperature R Raw temperature (MSB+LSB)

Timekeeping

  • Ticks advance in sync with the CPU cycle count
  • Each second of real time = emulated cycles / clock speed
  • Supports setting time via register writes
  • BCD format throughout (matching real DS3231)

Implementation

Located in CmosCpu.Devices/RtcDevice.cs:

  • Implements IBusDevice and IClockedDevice
  • Internal state tracks seconds, minutes, hours, day, date, month, year
  • Handles month lengths and leap year correctly
  • Read-only temperature register returns simulated value (0x18 = 24°C)

Integration

The RTC is used in:

  • Apple-1 machine configuration for time display
  • Retro70 computer as a standard I/O device
  • Any machine that includes it in its profile

See Also

Clone this wiki locally