This discussion about interrupts remind me of how to manage the real time clock in games. In some variants of C I have seen a function that can track time down to microseconds called NAME gettimeofday - get the date and time SYNOPSIS #include <sys/time.h> int gettimeofday(struct timeval *restrict tp, void *restrict tzp); DESCRIPTION The gettimeofday() function shall obtain the current time, expressed as seconds and microseconds since the Epoch, and store it in the timeval structure pointed to by tp. The resolution of the system clock is unspecified. If tzp is not a null pointer, the behavior is unspecified. RETURN VALUE The gettimeofday() function shall return 0 and no value shall be reserved to indicate an error. ERRORS No errors are defined. The <sys/time.h> header shall define the timeval structure that includes at least the following members: time_t tv_sec Seconds. suseconds_t tv_usec Microseconds. The tv_usec needs to hold values from 0 to 999999 The tv_sec just needs to be able to show seconds. This can start from 0 if no realtime clock is availabe and from EPOCH if a realtime clock exists. So every time I get a VBL interrupt in the Lynx I could add 13333 us to tv_usec. .interruptor system_clock_irq system_clock_irq: lda INTSET ; Poll all pending interrupts and #VBL_INTERRUPT beq irqend ; Exit if not a VBL interrupt ... write code to increment tv_usec tv_sec by 13333 usec irqend: clc rts Would this be a good addition to the C-library? At least it is more usable in games than time(). -- Karri ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo@musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.Received on Wed Jan 18 20:35:13 2012
This archive was generated by hypermail 2.1.8 : 2012-01-18 20:35:17 CET