From f723147f04f19ddc7e39bad9211a6f26082ffbc5 Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Sun, 25 Oct 2020 14:06:44 +0100
Subject: [PATCH] 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.
---
include/time.h | 46 ++++++++++++----------------------------
libsrc/atari/clock.s | 8 ++++---
libsrc/atari5200/clock.s | 1 -
libsrc/lynx/clock.s | 14 +++++-------
4 files changed, 24 insertions(+), 45 deletions(-)
diff --git a/include/time.h b/include/time.h
index 4ee658da9..49d7e6870 100644
--- a/include/time.h
+++ b/include/time.h
@@ -83,46 +83,31 @@ extern struct _timezone {
-#if defined(__ATARI__)
-/* The clock depends on the video standard, so read it at runtime */
-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 */
+#if defined(__ATARI5200__)
+# define CLOCKS_PER_SEC 60
#elif defined(__ATMOS__)
-# define CLK_TCK 100 /* POSIX */
-# define CLOCKS_PER_SEC 100 /* ANSI */
+# define CLOCKS_PER_SEC 100
#elif defined(__CBM__)
# if defined(__CBM510__) || defined(__CBM610__)
/* The 510/610 gets its clock from the AC current */
-# define CLK_TCK 50 /* POSIX */
-# define CLOCKS_PER_SEC 50 /* ANSI */
+# define CLOCKS_PER_SEC 50
# else
-# define CLK_TCK 60 /* POSIX */
-# define CLOCKS_PER_SEC 60 /* ANSI */
+# define CLOCKS_PER_SEC 60
# endif
#elif defined(__NES__)
-# define CLK_TCK 50 /* POSIX */
-# define CLOCKS_PER_SEC 50 /* ANSI */
+# define CLOCKS_PER_SEC 50
#elif defined(__PCE__)
-# define CLK_TCK 60 /* POSIX */
-# define CLOCKS_PER_SEC 60 /* ANSI */
+# define CLOCKS_PER_SEC 60
#elif defined(__GAMATE__)
-# define CLK_TCK 135 /* POSIX */ /* FIXME */
-# define CLOCKS_PER_SEC 135 /* ANSI */ /* FIXME */
+# define CLOCKS_PER_SEC 135 /* FIXME */
#elif defined(__GEOS__)
-# define CLK_TCK 1 /* POSIX */
-# define CLOCKS_PER_SEC 1 /* ANSI */
-#elif defined(__LYNX__)
-/* The clock-rate depends on the video scan-rate;
-** so, read it at run-time.
-*/
-extern clock_t _clk_tck (void);
-# define CLK_TCK _clk_tck()
-# define CLOCKS_PER_SEC _clk_tck()
+# define CLOCKS_PER_SEC 1
+#else
+/* Read the clock rate at runtime */
+clock_t _clocks_per_sec (void);
+# define CLOCKS_PER_SEC _clocks_per_sec()
#endif
+#define CLK_TCK CLOCKS_PER_SEC
#define CLOCK_REALTIME 0
@@ -149,6 +134,3 @@ int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp);
/* End of time.h */
#endif
-
-
-
diff --git a/libsrc/atari/clock.s b/libsrc/atari/clock.s
index e04416c18..853870520 100644
--- a/libsrc/atari/clock.s
+++ b/libsrc/atari/clock.s
@@ -3,7 +3,7 @@
; originally by Ullrich von Bassewitz and Sidney Cadot
;
; clock_t clock (void);
-; unsigned _clocks_per_sec (void);
+; clock_t _clocks_per_sec (void);
;
.export _clock, __clocks_per_sec
@@ -30,8 +30,10 @@
.proc __clocks_per_sec
- ldx #$00 ; Clear high byte of return value
- lda PAL ; use hw register, PALNTS is only supported on XL/XE ROM
+ ldx #$00 ; Clear byte 1 of return value
+ 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
bne @NTSC
lda #50
diff --git a/libsrc/atari5200/clock.s b/libsrc/atari5200/clock.s
index f2ef85b0b..fff766093 100644
--- a/libsrc/atari5200/clock.s
+++ b/libsrc/atari5200/clock.s
@@ -2,7 +2,6 @@
; from Atari computer version by Christian Groessler, 2014
;
; clock_t clock (void);
-; unsigned _clocks_per_sec (void);
;
.export _clock
diff --git a/libsrc/lynx/clock.s b/libsrc/lynx/clock.s
index dbccb32cb..e29799df6 100644
--- a/libsrc/lynx/clock.s
+++ b/libsrc/lynx/clock.s
@@ -2,18 +2,14 @@
; 2003-04-13, Ullrich von Bassewitz
; 2012-02-06, Greg King
;
-; #include
+; clock_t clock (void);
+; clock_t _clocks_per_sec (void);
;
-; typedef unsigned long int clock_t;
-; 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".
+; clocks_per_sec()'s test-values are based on the numbers in "set_tv.s".
; 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)
.constructor init_clock
@@ -42,7 +38,7 @@
;-----------------------------------------------------------------------------
; Return the number of clock ticks in one second.
;
-__clk_tck:
+__clocks_per_sec:
ldx #$00 ; >50, >60, >75
ldy PBKUP
lda #<75