SYSTEM.DRV and the Windows Timer

The Windows timer is a relatively simple extension of the timer logic built into the IBM PC's hardware and ROM BIOS. The PC's ROM BIOS initializes an Intel 8259 timer chip to generate the hardware Interrupt 08H. This interrupt is sometimes called the ”clock tick“ or ”timer tick“ interrupt. An Interrupt 08H occurs every 54.925 msec, or about 18.2 times per second. Among other purposes, the BIOS uses Interrupt 08H to update a ”time-of-day“ value stored in the BIOS data area. MS-DOS uses this value to calculate the current time.

The SYSTEM.DRV driver located in the SYSTEM subdirectory of your Windows directories handles hardware timer interrupts. SYSTEM.DRV sets a new Interrupt 08H vector address during initialization and restores the original vector address before Windows terminates. The Interrupt 08H routine within SYSTEM.DRV calls the original Interrupt 08H handler before doing its own processing so that underlying system functions that require this interrupt will continue to work normally.

When SYSTEM.DRV receives an Interrupt 08H, it calls a routine within the USER module of Windows that decrements counters for each timer set by Windows applications. When a counter reaches 0, USER places a WM_TIMER message in that application's message queue and resets the counter to the original value.

Because a Windows application retrieves WM_TIMER messages from the normal message queue, you never have to worry about your program being ”interrupted“ by a sudden WM_TIMER message while doing other processing. In this way, the timer is similar to the keyboard and mouse: The driver handles the asynchronous hardware interrupt events, and Windows translates these events into orderly, structured, serialized messages.

SYSTEM.DRV does not attempt to reprogram the 8259 timer chip in the IBM PC. The Windows timer has the same 54.925-msec resolution as the underlying PC timer. This fact has two important implications:

A Windows application cannot receive WM_TIMER messages at a rate faster than about 18.2 times per second when using a single timer.

The time interval you specify in the SetTimer call is always rounded down to an integral multiple of clock ticks. For instance, a 1000-msec interval divided by 54.925 msec is 18.207 clock ticks, which is rounded down to 18 clock ticks, which is really a 989-msec interval. For intervals less than 55 msec, each clock tick generates a single WM_TIMER message.

Do not attempt to intercept the ROM BIOS timer interrupt in your Windows programs. Use the Windows timer instead.