Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

TI

Keyword Abbreviation Token (hex) Version(s) Classification
TI none 54 49 1.0+ Reserved variable
* The "token" is really just the character codes for the letters "TI"

 
  Syntax  
TI
 
Returns Type Value(s) Note(s)
timeJiffies Float
0 ~ 5183999
The value will be an integer 
 
  Purpose  
Get the system time.
 
  Remarks  
This is the numeric version of the BASIC time variable.  The timeJiffies is (obstensibly) the number of "jiffies" since the system was powered-on or the Jiffy Clock was set to zero (by natural roll-over or explicit assignment).  The returned value is always a mathematical integer (no fraction) but is a BASIC floating type; in particular, many values of TI can not be assigned to an integer variable (which are limited to a maximum of 32767).  Like most reserved variables, attempts to assign a value to TI will cause a SYNTAX ERROR.
 
A "jiffy" is a unit of time equal to 1/60 of a second.  So there are 60 jiffies per second (very similar to minutes, and seconds).  The system "Jiffy Clock" operates by adding 1 to a "jiffy counter" (which you can think of as TI) at a periodic rate on NTSC systems.  On most PAL systems, where the system update occurs 50 times per second, a bit of trickery is used: each 5th "jiffy" the system actually increments the "jiffy counter" twice!  On the one hand, this means that even PAL systems will have 60 jiffies per second.  On the other hand, the BASIC programmer must be careful not to test for a specific value because it may be skipped!  Another technical note: at least one (obscure) version of PAL actually has 60 interrupts per second (so no values are skipped).  Whether or not the jiffy clock will skip every fifth value corresponds with the NTSC / PAL secret variable.
 
The system will reset the "jiffy counter" to zero once it reaches 5184000 jiffies or greater.  This is equivalant to 24 hours (i.e., 24 hours * 60 minutes/hour * 60 seconds/minute * 60 jiffies/second).  You should normally never see this value returned by TI, however you may see this value (or greater) for a brief moment before the next "jiffy counter" update by the system IRQ if you assign an "bad value" to TI$ (see examples).
 
The returned timeJiffies is pretty good for computer use, but rather meaningless to the average user.  Conversion to and from a more convient format, like Hours:Minutes:Seconds is rather tedious in CBM BASIC.  Fortunately, CBM BASIC also provides a string version (called TI$) which is HHMMSS format.
 
Because the returned value is measured in fractions of a second, very precise timings (for a human) can be accomplished, assuming BASIC is fast enough.  The TI variable is (obstensibly) 60 times more precise than the string version, TI$.
 
Like all BASIC variables, only the first two characters of the name are significant.  So you may also use (and early documentation shows) TIME if you prefer (note the M and E are superfluous).
 
On most (all?) of the CBM 8-bits, the system time is mainted by software in the KERNAL, even though some machines have hardware which is more reliable.  In particular, delays in communicating with external devices (and a few internal operations) will cause the system time to "fall behind" reality (i.e., run slow).  Generally the more I/O operations that take place, the less reliable the software clock.
 
The C128 has FAST and SLOW commands to change the CPU speed, and thus the speed of BASIC execution, but the Jiffy Clock works the same at either speed.
 
Unfortunately, none of the CBM BASICs have a DATE variable or function.  So you would need to periodically check the TI for "rollover" to detect a change in the date.
 
Examples:
TI$ = "000000" : PRINT TI
 0

READY.
TI$ = "000000" : FOR I = 1 TO 1000: NEXT : PRINT TI
 62         value may vary a bit on different machines

READY.
TI$ = "000001" : PRINT TI : REM 1 second
 60

READY.
TI$ = "000100" : PRINT TI : REM 1 minute
 3600

READY.
TI$ = "010000" : PRINT TI : REM 1 hour
 216000

READY.
TI$ = "239999" : PRINT TI : FOR I=1 TO 10 : NEXT : PRINT TI
 5330340
 0         value may vary a bit on different machines

READY.
 
  Compare With  
 
  See Also  

© H2Obsession, 2014
Comments