Timers using CC65

Tutorials and help articles.

(Posts require approval. See pinned post.)
Forum rules
Post guides, tutorials, and other instructional content here.

This topic area requires approval, so please be patient while we review content to make sure it fits the expectations for this topic area.

Tech support questions should be asked in Hardware or Software support.
Post Reply
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

Timers using CC65

Post 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.

 

Collin
Posts: 2
Joined: Sun Oct 23, 2022 5:51 am

Timers using CC65

Post 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.

Post Reply