System timers

References


- Memory map taken from the book Mapping The Atari - Revised Edition (article Memory Map)

System timer memory address map


LOCATION
DECIMAL (HEX)
LABEL DESCRIPTION
18, 19, 20
($12, $13, $14)
RTCLOK Internal realtime clock. Location 20 increments every stage one VBLANK interrupt (1/60 second = one jiffy) until it reaches 255 ($FF); then location 19 is incremented by one and 20 is reset to zero (every 4.27 seconds). When location 19 reaches 255, it and 20 are reset to zero and location 18 is incremented by one (every 18.2 minutes or 65536 TV frames). To use these locations as a timer of seconds, try:

TIME = INT((PEEK(18) * 65536 + PEEK(19) * 256 + PEEK(20) )/60)

To see the count in jiffies, eliminate the "/60" at the end. To see the count in minutes, change "/60" to "/360." The maximum value of the RT clock is 16,777,215. When it reaches this value, it will be reset to zero on the next VBLANK increment. This value is the result of cubing 256 (i.e., 256 * 256 * 256), the maximum number of increments in each clock register. The RT clock is always updated every VBLANK regardless of the time-critical nature of the code being processed.
77 ($4D) ATRACT Attract mode timer and flag. Attract mode rotates colors on your screen at low luminance levels when the computer is on but no keyboard input is read for a long time (seven to nine minutes). This helps to save your TV screen from "burn-out" damage suf- fered from being left on and not used. It is set to zero by IRQ whenever a key is pressed, otherwise incremented every four seconds by VBLANK (see locations 18 - 20; $12 - $14). When the value in ATRACT reaches 127 ($7F), it is then set to 254 ($FE) un- til attract mode is terminated. This sets the flag to reduce the luminance and rotate the colors when the Atari is sitting idle. POKE with 128 ($80) to see this effect immediately: it normally takes seven to nine minutes to enable the attract mode. The OS cannot "attract" color generated by DLI's, although your DLI routine can, at a loss of time.

Joysticks alone will not reset location 77 to zero. You will have to add a POKE 77,0 to your program periodically or frequently call in a subroutine to prevent the Atari from entering attract mode if you are not using any keyboard input.
528,529
($210, $211)
VTIMR1 POKEY timer one interrupt vector, initialized to 59314 ($E7B2), which is a PLA, RTI instruction sequence. Timer interrupts are established when the POKEY timer AUDF1 (53760; $D200) counts down to zero. Values in the AUDF registers are loaded into STIMER at 53769 ($D209). IRQ.
530,531
($212, $213)
VTIMR2 POKEY timer two vector for AUDF2 (53762, $D202), initialized to 59314 ($E7B2). IRQ.
532,533
($214, $215)
VTIMR4 POKEY timer four vector for AUDF4 (53766, $D206), initialized to 59314 ($E7B2). This IRQ is only vectored in the "B" version of the OS ROMs.
536,537
($218, $219)
CDTMV1 System timer one value. Counts backwards from 255. This SIO timer is decremented every stage one VBLANK. When it reaches zero, it sets a flag to jump (JSR) through the address stored in locations 550, 551 ($226, $227). Only the realtime clock (locations 18-20; $12-14), timer one, and the attract mode register (77; $4D) are updated when the VBLANK routine is cut short because time-critical code (location 66; $42 set to non-zero for critical code) is executed by the OS. Since the OS uses timer one for its I/O routines and for timing serial bus operations (setting it to different values for timeout routines), you should use another timer to avoid conflicts or interference with the operation of the system.
538,539
($21A, $21B)
CDTMV2 System timer two. Decremented at the stage two VBLANK. Can be decremented every stage one VBLANK, subject to critical section test as defined by setting of CRITIC flag (location 66; $42). This timer may miss (skip) a count when time-critical code (CRITIC equals non-zero) is being executed. It performs a JSR through location 552, 553 ($228, $229) when the value counts down to zero.
540,541
($21C, $21D)
CDTMV3 System timer three. Same as 538. Timers three, four, and five are stopped when the OS sets the CRITIC flag to non-zero as well. The OS uses timer three to OPEN the cassette recorder and to set the length of time to read and write tape headers. Any prior value in the register during this function will be lost.
542,543
($21E, $21F)
CDTMV4 System timer four. Same as 538 ($21A)
544,545
($220, $221)
CDTMV5 System timer five. Same as 538 ($21A). Timers three, four, and five all set flags at 554, 556 and 558 ($22A, $22C, $22E), respectively, when they decrement to zero.
550,551
($226, $227)
CDTMA1 System timer one jump address, initialized to 60400 ($EBF0). When locations 536, 537 ($218, $219) reach (count down to) zero, the OS vectors through here (jumps to the location specified by these two addresses). You can set your machine code routine address here for execution when timer one reaches (counts down to) zero. Your code should end with the RTS instruction. Problems may occur when timer values are set greater than 255, since the 6502 cannot manipulate 16-bit values directly (a number in the range of zero to 255 is an eight-bit value; if a value requires two bytes to store, such as a memory location, it is a 16-bit value). Technically, a VBLANK interrupt could occur when one timer byte is being initialized and the other not yet set. To avoid this, keep timer values less than 255. See the Atari OS User's Manual, page 106, for details.

Since the OS uses timer one, it is recommended that you use timer two instead, to avoid conflicts with the operation of the Atari. Initialized to 60396 ($EBEA) in the old ROMs, 60400 ($EBF0) in the new ROMs. NMI
552,553
($228, $229)
CDTMA2 System timer two jump address. Not used by the OS, available to user to enter the address of his or her own routine to JMP to when the timer two (538, 539; $21A, $21B) count reaches zero. Initialized to zero; the address must be user specified. NMI
554
($22A)
CDTMF3 System timer three flag, set when location 540, 541 ($21C, $21D) reaches zero. This register is also used by DOS as a timeout flag.
555
($22B)
SRTIMR Software repeat timer, controlled by the IRQ device routine. It establishes the initial 1/2 second delay before a key will repeat. Stage two VBLANK establishes the 1/10 second repeat rate, decrements the timer and implements the auto repeat logic. Every time a key is pressed, STIMER is set to 48 ($30). Whenever SRTIMR is equal to zero and a key is being continuously pressed, the value of that key is continually stored in CH, location 764 ($2FC).
556
($22C)
CDTMF4 System timer four flag. Set when location 542, 543 ($21E, $21F) counts down to zero.
558
($22E)
CDTMF5 System timer five flag. Set when location 558, 559 ($22E, $22F) counts down to zero.
53769
($D209)
STIMER Start the POKEY timers (the AUDF registers). You POKE any non-zero value here to load and start the timers; the value isn't itself used in the calculations. This resets all of the audio frequency dividers to their AUDF values. If enabled by IRQEN below, these AUDF registers generate timer interrupts when they count down from the number you POKEd there to zero. The vectors for the AUDF1, AUDF2 and AUDF4 timer interrupts are located between 528 and 533 ($210 and $215). POKEY timer four interrupt is only enabled in the new "B" OS ROMs.
53774
($D20E)
IRQEN To be described...
58460
($E45C)
SETVBV To be described...
59345
($E7D1)
SYSVBL To be described...
59666
($E912)
SETVBL To be described...