TIME: Your Commodore 64's Stopwatch

TIME: Your Commodore 64's Stopwatch

Want to add a timekeeping element to your Commodore 64 programs? Need to track how long events take or create time-based interactions? Look no further than the TI and TI$ system variables, your C64's built-in stopwatch! These handy tools keep track of the time elapsed since you last turned on or reset your computer.

TI and TI$: A Dynamic Duo

  • TI: A numeric variable that stores the elapsed time in "jiffies" (1/60th of a second). You can use TI for precise timing calculations and comparisons.
  • TI$: A string variable that represents the time in a human-readable format (HHMMSS), displaying hours, minutes, and seconds.

Syntax (Reading TIME)

You don't need a special command to access the current time. Just use the TI or TI$ variables in your code:

10 PRINT TI   :rem Print the time in jiffies
20 PRINT TI$  :rem Print the time in HHMMSS format (e.g., "123456")

Syntax (Setting TIME)

TI$ = "<new time>"

Where: - <new time>: A six-character string in the format HHMMSS (e.g., "123456" sets the time to 12 hours, 34 minutes, and 56 seconds).

Applications

The TI and TI$ variables are invaluable for:

  • Timing events: Measure how long it takes for a user to react, for a loop to complete, or for a game level to finish.
  • Creating time-based interactions: Trigger events or change behavior at specific times or intervals.
  • Displaying the time: Show the current time on the screen as part of a clock or other application.
  • Seeding random number generators: Use the changing value of TI to seed the RND function for more varied results.

Code Examples

1. Simple Timer:

10 TI$="000000"               :rem Reset the time
20 PRINT TI$     
30 FOR I = 1 TO 1800 : NEXT I :rem Wait for 30 seconds (1800 jiffies)
40 PRINT TI$                  :rem Print the elapsed time

This prints the time (000000), then waits for 30 seconds before printing the time again (000030)

2. Stopwatch:

10 INPUT "Press Enter to start the stopwatch"; A$
20 T1=TI :rem Store the starting time
30 INPUT "Press Enter to stop"; A$
40 PRINT "Elapsed time (seconds): "; (TI-T1)/60

This code measures the elapsed time between two key presses in seconds.

TIME in the Wild: The Commodore 64 Alarm Clock

Imagine you want to turn your C64 into an alarm clock. You could use the TI$ variable to track the current time and trigger an alarm sound (using a SOUND user function) when the time matches a preset alarm time.

Don't let time slip away! With TI and TI$, you have the power to measure, manipulate, and display time in your Commodore 64 programs. It's like having a built-in timekeeper for your code, allowing you to create time-aware applications and add a new dimension of interactivity. So embrace the concept of time in your programming and let your C64 become your personal time machine!


Privacy Policy

Let's be honest, we collect some data. But we promise not to sell it, we'll mostly use it to improve our service. You can read the nitty-gritty details below, but be warned, it uses big words that lawyers like (we don't judge).

By using our service, you agree to this privacy policy. This disclaimer strikes a balance between lightheartedness and informing users that they should still read the full privacy policy if they choose.