Page 1 of 1

Timers using CC65

Posted: Thu Oct 14, 2021 4:30 pm
by rje

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.

 


Timers using CC65

Posted: Sun Oct 23, 2022 7:12 pm
by Collin

Hello rje,

 

I am running Release 41 ("Marrakech") of x16emu and cc65 - 2.19

If I call clock_gettime() I get 1445 from both tv_sec and tv_nsec

What I am trying to create is a delta Time or time between to frames I am using vsync assembly to get timing from the display.



I am very new to all of this and not sure what the correct question to ask in the search.

Thanks in advance.