How MS-DOS 6.22 Sets Time via RTC Hardware

MS-DOS 6.22 maintains and sets system time by coordinating between low-level x86 hardware, the ROM BIOS, and internal DOS interrupt services. Rather than directly accessing the Real-Time Clock (RTC) registers during standard runtime, the operating system relies on BIOS Interrupt 1Ah and the 8253/8254 Programmable Interval Timer (PIT) to bridge user-space requests with persistent battery-backed hardware. This article examines the architectural flow, interrupt routines, and hardware interactions MS-DOS 6.22 executes when a user or program updates the system time.

The Dual-Clock Architecture

IBM PC-compatible systems running MS-DOS 6.22 maintain two separate timekeeping mechanisms:

  1. The Active Runtime Clock: Managed by the Intel 8253 or 8254 PIT. The PIT fires hardware interrupt IRQ 0 approximately 18.2065 times per second (a frequency of 1.19318 MHz divided by 65,536). The BIOS handler for IRQ 0 (INT 08h) updates a 32-bit tick counter located in the BIOS Data Area (BDA) at memory address 0040:006Ch.
  2. The Persistent Real-Time Clock (RTC): An independent, battery-backed chip (historically the Motorola MC146818 or compatible chip integrated into the motherboard chipset). It tracks seconds, minutes, hours, day of the week, date, month, and year in non-volatile CMOS RAM, even when the computer is powered down.

MS-DOS relies on the PIT tick counter for daily operations and file timestamps, but it synchronizes with the RTC to ensure time persists across reboots.

The Software Interface: INT 21h, Function 2Dh

When a user modifies the system time using the TIME command in COMMAND.COM, or when an application updates the clock, MS-DOS exposes the software interrupt INT 21h, Function 2Dh (Set System Time).

To call this function, the registers are loaded as follows:

  • AH = 2Dh
  • CH = Hour (0–23)
  • CL = Minute (0–59)
  • DH = Second (0–59)
  • DL = Hundredths of a second (0–99)

Once invoked, the MS-DOS kernel validates the values. If the numbers are outside valid chronological ranges, the routine returns AL = FFh (failure). If valid, MS-DOS converts the specified hours, minutes, and seconds into the equivalent number of 18.2 Hz timer ticks and updates the 32-bit tick count in the BIOS Data Area (0040:006Ch), as well as the midnight rollover flag at 0040:0070h.

Bridging to Hardware: BIOS INT 1Ah

Updating the tick counter only alters the volatile system time in RAM. To write these changes permanently into the RTC hardware, MS-DOS 6.22 makes a call to the ROM BIOS using INT 1Ah.

MS-DOS invokes INT 1Ah, Function 03h (Set Real-Time Clock Time):

  • AH = 03h
  • CH = Hours in Binary-Coded Decimal (BCD)
  • CL = Minutes in BCD
  • DH = Seconds in BCD
  • DL = Daylight Saving Time flag (00h for standard time, 01h for daylight time)

Before issuing this interrupt, MS-DOS translates the standard binary values provided in the original INT 21h call into BCD format, which the RTC hardware architecture expects.

Direct RTC Hardware Interaction

The ROM BIOS handles the physical interaction with the RTC chip on behalf of MS-DOS. The MC146818 RTC communicates via two I/O ports:

  • Port 70h (Index/Address Port): Selects the target CMOS register. The highest bit (bit 7) is also used to disable or enable Non-Maskable Interrupts (NMIs).
  • Port 71h (Data Port): Reads from or writes to the selected register.

When the BIOS executes INT 1Ah, AH=03h, it performs the following sequence:

  1. Disables Interrupts: Executes the CLI instruction to prevent an incoming hardware interrupt from disrupting the register sequence.
  2. Halts RTC Updates: The BIOS reads Register 0Bh (Control Register B) by outputting 0Bh to port 70h, reads the current value via port 71h, and sets the "Update Inhibit" bit (bit 7). This stops the RTC from updating its internal time counters while the new time is written, preventing corrupt data.
  3. Writes Time Values: The BIOS addresses individual RTC data registers via port 70h and writes the BCD values using port 71h:
    • Register 00h: Seconds
    • Register 02h: Minutes
    • Register 04h: Hours
  4. Resumes RTC Updates: The BIOS clears the Update Inhibit bit in Control Register 0Bh, allowing the chip to resume regular timekeeping from the newly configured baseline.
  5. Re-enables Interrupts: Executes STI to restore normal CPU interrupt processing.

Through this layered abstraction—from INT 21h down to INT 1Ah and the 0x70/0x71 I/O ports—MS-DOS 6.22 ensures that both the internal memory-based timer ticks and the hardware-level CMOS clocks stay synchronized.