TIME$

From C64-Wiki
(Redirected from TI$)
Jump to navigationJump to search
BASIC variable
Variable-Name: TIME$
Type: System variable
List of all BASIC keywords


Remark: This article describes the BASIC command TIME$ in BASIC V2 of the Commodore 64.

Type: System variable as string
General Programming-Syntax: TIME$ or TI$

The system variable TI$ contains a six-character string that indicates the running time of the computer since the last reset, an overflow after 24 hours or the time since the last assignment in hours, minutes and seconds (format: HHMMSS).

This variable is often also referred to as TIME$ or TIMER$ by convention in a long form that is possible and valid for variable names - no other keyword can be used - in order to increase readability.

The time counting starts at "000000" when switching on, after overflow after 24 hours or after a reset. In addition, the variable TI$ can be assigned a 6-digit character string to set a corresponding time value. For example, given TI$="000000"the time count resets to the power-on state.

The character string in TI$ corresponds to the value of the system variable TI (or TIME ), both of which are based on the system-internal timer (time counter). Setting TI$ also sets TI to the corresponding value in 1/60 s.

The system variable TI$ can have values ​​from "000000" to "235959". In the event of a range overflow, TI$ again has the value "000000" and therefore TI also contains the value 0. Although "235959" is considered the largest value to be read, TIME$ can be set to a maximum of "774020". If TIME$ is assigned a string value in the range "774021" to "999999", the value TIME$ results in the value entered minus 774021. For example, the sequence TI$="888888":?TI$ outputs "114907", where 888888-774021 then results in 114867, which again after converting the 67 seconds to 1 minute and 7 seconds eventually leads to 114907.

The time recorded by TI$ usually does not correspond to the progression of real time, since the internal timer is implemented using interrupt technology. So, for example, when using the datasette or during other processes that mask interrupts ( IRQ ) (e.g. with SEI ) the timer is temporarily stopped.

If no character string is used when setting TI$, the BASIC error message ?TYPE MISMATCH ERROR is displayed. If the assigned character string does not meet certain requirements (e.g. does not have 6 characters or contains forbidden characters such as "-", "+"), the error message ?ILLEGAL QUANTITY ERROR is shown. However, meaningful characters and value ranges are not strictly checked and so TI$ (and therefore also TI) can briefly assume a value outside the permissible range, which then jumps back to "000000" within 1/60 of a second.

The typical situation that triggers the above error occurs when using string variable names that have TI in the significant first two letters, such as TITLE$ = "C64 Internals - The Big Book of the Commodore 64".

Examples[edit | edit source]

Digital clock[edit | edit source]

10 REM Clock simulation, cancel with RUN/STOP
20 TIME$="235800" : REM Setting a new time for overflow!
30 T$=TIME$ : REM Save the time to avoid a overflow!
40 PRINT CHR$(147);
50 PRINT LEFT$(T$,2);":";
60 PRINT MID$(T$,3,2);":";
70 PRINT RIGHT$(T$,2)
80 GOTO 30

The updated time is shown at the upper, left corner on the screen.

Time delay[edit | edit source]

100 TI$="000000"
110 WAIT 162,64

This program waits approx. 1 second by means of using a trick with the WAIT command: it is awaiting a change of the low byte timer value at bit 6 from 0 to 1. After the low byte is set to 0 and the timer counts to 64, which takes 64 jiffies (64/60 sec.). This code won't break by pushing RUN/STOP , just with RUN/STOP +RESTORE  combination.


BASIC V2.0 (second release) Commands

ABS | AND | ASC | ATN | CHR$ | CLOSE | CLR | CMD | CONT | COS | DATA | DEF | DIM | END | EXP | FN | FOR | FRE | GET | GET# | GOSUB | GOTO | IF | INPUT | INPUT# | INT | LEFT$ | LEN | LET | LIST | LOAD | LOG | MID$ | NEW | NEXT | NOT | ON | OPEN | OR | PEEK | π | POKE | POS | PRINT | PRINT# | READ | REM | RESTORE | RETURN | RIGHT$ | RND | RUN | SAVE | SGN | SIN | SPC | SQR | STATUS/ST | STEP | STOP | STR$ | SYS | TAB | TAN | THEN | TIME/TI | TIME$/TI$ | TO | USR | VAL | VERIFY | WAIT