|List of all BASIC keywords|
Type: Numeric system variable General Programming-Syntax: TIME or TI
The system variable TIME (short: TI) is an interval timer counting "jiffies" (1/60 second increments). It is normally incremented during the standard 1/60th-second CIA1-generated IRQ service routine (typically by means of the Kernal UDTIM routine). This "manually" operated timer has nothing to do with either CIA's TOD clock.
Note that TIME follows just the expanded variable name scheme and therefore any character suitable as variable name (letter, digit) after TI is silently ignored, for example TICKAMASALA will still refer to TI. The common usage how it can be found in program listing is the short variant TI.
The time is initialized to 0 at power-on or reset. TI is also affected by the setting of the system variable TIME$, as they are actually based on the same internal timer and carry the same time just in different representations (see TIME$ for details).
TIME variable wraps around (restarts at 0) every 24 hours at midnight, meaning 1 second after TIME$ reaches the value "23:59:59". Just before that moment, TIME will reach its maximum value: 5183999 (=24*60^3 -1), equivalent to 24 hours, measured in jiffies. After wrapping around, TIME continues counting up from 0 again.
TIME is not completely accurate, because it can fall behind during I/O operations, and any time the system IRQ is disabled. When reading or writing to the datasette, the interval-timer is temporarily stopped. When communicating over the IEC bus, a small number of jiffies will be lost.
The system variable TIME is read-only, and cannot be set. An attempt to assign to TIME will result in the BASIC error ?SYNTAX ERROR. Variable TIME$ can however be set and the TIME variable will follow.
TI$="000000" will set TI to 0,
TI$="000001" sets TI to 60 and so on.
Examples[edit | edit source]
Simple usage[edit | edit source]
Using PEEK for read TIME[edit | edit source]
Name resolving[edit | edit source]
Another example for TI.
This is a buggy code with an embedded token TO. This BASIC code prints out the following on the screen (the syntax error appears delayed, because TICK is a valid variable name, but the token appears unexpected):
43580 ?SYNTAX ERROR READY.
Time delay[edit | edit source]
A delay subroutine in line 900 taking the contents of variable T as parameter for the amount of time to wait:
100 PRINT "START "TI$": T=2.5: GOSUB 900: PRINT "END TIME: "TI$ 199 END 900 T0=TI: FOR T=T0+T*60 TO T: T=TI:T=T-5184E3*(T<T0): NEXT: RETURN
The elapsed time in seconds can be retrieved by using the expression
The end value for the FOR-NEXT construction is derived from variable T, which is previously set to the final time value during the initial assignment for the start value.
Expression -5184E3*(T<T0) compensates for the wrap-around on the 24 hour tick count (60 ticks/seconds * 86400 seconds/day). (T<T0) evaluates to -1 if true.
Links[edit | edit source]
- IRQ-Routine (on AAY64), for the computer clock.
- $FFEA/65514 KERNAL start UDTIM for increasing the timer.
- $FFDE/65502 KERNAL start RDTIM for reading the timer.
- $FFDB/65499 KERNAL start SETTIM for setting the timer.