160-162

From C64-Wiki
Jump to navigationJump to search

The zeropage addresses 160–162 ($A0–$A2 in hexadecimal) holds the jiffy clock; the clock "mechanism" underlying the TIME and TIME$ system variables. These three addresses form a 24-bit binary integer "equivalent" of the timer count obtained through the TIME system variable, albeit in a rather unusual convention in that the first of the three bytes, address 160/$A0, holds the most significant byte, followed by the "intermediately significant" byte held in address 161/$A1, and finally the least significant byte at the last address; 162/$A2.

Just as the timer value obtained from TIME represents the number of 1/60'th of a second elapsed since midnight (or more likely since last power-on or reset), so does the integer in 160–162 – the part of BASIC ROM that handles the TIME system variable simply pulls the current value from these addresses.

Although the jiffy clock may be set through manipulating the contents of 160–162 from BASIC, it is much easier to do this by assigning a time-of-day to the TIME$ system variale: Since the standard IRQ interrupt service routine updates the clock 60 times a second, asynchronously with respect to the BASIC program, it is necessary (both for BASIC and machine language programs) to disable this interrupt whilst setting the new time-of-day, to avoid the service routine "updating" the clock while this is taking place.