Timers using CC65
Posted: Thu Oct 14, 2021 4:30 pm
I've started learning how time is measured on the X16.
In particular, I've been playing with clock_gettime() from <time.h>. It includes a timespec structure that looks like this:
/* Structure for seconds and nanoseconds */
struct timespec {
time_t tv_sec; // <-- that's an unsigned long
long tv_nsec;
};
I've been fetching the time like this:
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
And, if I read the results correctly, the response is probably measuring to milliseconds. I think this, because when I print tv_nsec, there's three digits of precision followed by six zeros.
I also tried shifting tv_nsec right by 10 bits, which results in what APPEARS to be six digits of precision -- but that would imply that the clock can measure microseconds. And, upon reflection, I doubt it. I think shifting bits results in a false reading because it's dividing by a non-decimal value. So, I think the call is measuring to milliseconds.
Assume it's not accurate to THE millisecond, either. I haven't checked that yet.