1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-11 20:29:36 +00:00

Streamlined clock rate handling.

* Docs say that CLK_TCK is an obsolete alias of CLOCKS_PER_SEC so there's no point in individual definitions.
* All targets determining the clock rate at runtime can use a common handling.
This commit is contained in:
Oliver Schmidt 2020-10-25 14:06:44 +01:00
parent 07cc6a3d20
commit f723147f04
4 changed files with 24 additions and 45 deletions

View File

@ -83,46 +83,31 @@ extern struct _timezone {
#if defined(__ATARI__) #if defined(__ATARI5200__)
/* The clock depends on the video standard, so read it at runtime */ # define CLOCKS_PER_SEC 60
unsigned _clocks_per_sec (void);
# define CLK_TCK _clocks_per_sec()
# define CLOCKS_PER_SEC _clocks_per_sec()
#elif defined(__ATARI5200__)
# define CLK_TCK 60 /* POSIX */
# define CLOCKS_PER_SEC 60 /* ANSI */
#elif defined(__ATMOS__) #elif defined(__ATMOS__)
# define CLK_TCK 100 /* POSIX */ # define CLOCKS_PER_SEC 100
# define CLOCKS_PER_SEC 100 /* ANSI */
#elif defined(__CBM__) #elif defined(__CBM__)
# if defined(__CBM510__) || defined(__CBM610__) # if defined(__CBM510__) || defined(__CBM610__)
/* The 510/610 gets its clock from the AC current */ /* The 510/610 gets its clock from the AC current */
# define CLK_TCK 50 /* POSIX */ # define CLOCKS_PER_SEC 50
# define CLOCKS_PER_SEC 50 /* ANSI */
# else # else
# define CLK_TCK 60 /* POSIX */ # define CLOCKS_PER_SEC 60
# define CLOCKS_PER_SEC 60 /* ANSI */
# endif # endif
#elif defined(__NES__) #elif defined(__NES__)
# define CLK_TCK 50 /* POSIX */ # define CLOCKS_PER_SEC 50
# define CLOCKS_PER_SEC 50 /* ANSI */
#elif defined(__PCE__) #elif defined(__PCE__)
# define CLK_TCK 60 /* POSIX */ # define CLOCKS_PER_SEC 60
# define CLOCKS_PER_SEC 60 /* ANSI */
#elif defined(__GAMATE__) #elif defined(__GAMATE__)
# define CLK_TCK 135 /* POSIX */ /* FIXME */ # define CLOCKS_PER_SEC 135 /* FIXME */
# define CLOCKS_PER_SEC 135 /* ANSI */ /* FIXME */
#elif defined(__GEOS__) #elif defined(__GEOS__)
# define CLK_TCK 1 /* POSIX */ # define CLOCKS_PER_SEC 1
# define CLOCKS_PER_SEC 1 /* ANSI */ #else
#elif defined(__LYNX__) /* Read the clock rate at runtime */
/* The clock-rate depends on the video scan-rate; clock_t _clocks_per_sec (void);
** so, read it at run-time. # define CLOCKS_PER_SEC _clocks_per_sec()
*/
extern clock_t _clk_tck (void);
# define CLK_TCK _clk_tck()
# define CLOCKS_PER_SEC _clk_tck()
#endif #endif
#define CLK_TCK CLOCKS_PER_SEC
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
@ -149,6 +134,3 @@ int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp);
/* End of time.h */ /* End of time.h */
#endif #endif

View File

@ -3,7 +3,7 @@
; originally by Ullrich von Bassewitz and Sidney Cadot ; originally by Ullrich von Bassewitz and Sidney Cadot
; ;
; clock_t clock (void); ; clock_t clock (void);
; unsigned _clocks_per_sec (void); ; clock_t _clocks_per_sec (void);
; ;
.export _clock, __clocks_per_sec .export _clock, __clocks_per_sec
@ -30,8 +30,10 @@
.proc __clocks_per_sec .proc __clocks_per_sec
ldx #$00 ; Clear high byte of return value ldx #$00 ; Clear byte 1 of return value
lda PAL ; use hw register, PALNTS is only supported on XL/XE ROM stx sreg ; Clear byte 2 of return value
stx sreg+1 ; Clear byte 3 of return value
lda PAL ; Use hw register, PALNTS is only supported on XL/XE ROM
and #$0e and #$0e
bne @NTSC bne @NTSC
lda #50 lda #50

View File

@ -2,7 +2,6 @@
; from Atari computer version by Christian Groessler, 2014 ; from Atari computer version by Christian Groessler, 2014
; ;
; clock_t clock (void); ; clock_t clock (void);
; unsigned _clocks_per_sec (void);
; ;
.export _clock .export _clock

View File

@ -2,18 +2,14 @@
; 2003-04-13, Ullrich von Bassewitz ; 2003-04-13, Ullrich von Bassewitz
; 2012-02-06, Greg King ; 2012-02-06, Greg King
; ;
; #include <time.h> ; clock_t clock (void);
; clock_t _clocks_per_sec (void);
; ;
; typedef unsigned long int clock_t; ; clocks_per_sec()'s test-values are based on the numbers in "set_tv.s".
; clock_t _clk_tck(void);
; #define CLOCKS_PER_SEC _clk_tck()
; clock_t clock(void);
;
; clk_tck()'s test-values are based on the numbers in "set_tv.s".
; If you change the numbers there, then change them here, too. ; If you change the numbers there, then change them here, too.
; ;
.export _clock, __clk_tck, clock_count .export _clock, __clocks_per_sec, clock_count
.interruptor update_clock, 2 ; (low priority) .interruptor update_clock, 2 ; (low priority)
.constructor init_clock .constructor init_clock
@ -42,7 +38,7 @@
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
; Return the number of clock ticks in one second. ; Return the number of clock ticks in one second.
; ;
__clk_tck: __clocks_per_sec:
ldx #$00 ; >50, >60, >75 ldx #$00 ; >50, >60, >75
ldy PBKUP ldy PBKUP
lda #<75 lda #<75