From 77d11ca4efaf6b131db2ef3d7e351751c275b059 Mon Sep 17 00:00:00 2001 From: bebbo Date: Mon, 12 Aug 2024 10:30:42 +0200 Subject: [PATCH] use ReadEClock instead of DateStamp to get milliseconds --- sources/nix/time/clock.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sources/nix/time/clock.c b/sources/nix/time/clock.c index e0efe0e..d6752b7 100644 --- a/sources/nix/time/clock.c +++ b/sources/nix/time/clock.c @@ -1,20 +1,27 @@ #include #include -#include #include +#include #include "stabs.h" -static struct DateStamp ds; +static struct EClockVal eval0; void __initclock(void) -{ DateStamp(&ds); } +{ + struct Device * TimerBase = DOSBase->dl_TimeReq->tr_node.io_Device; + ReadEClock(&eval0); +} ADD2INIT(__initclock,-10); clock_t clock(void) -{ struct DateStamp ds2; - DateStamp(&ds2); - return (((ds2.ds_Days-ds.ds_Days)*(24*60)+ - ds2.ds_Minute-ds.ds_Minute)*(60*TICKS_PER_SECOND)+ - ds2.ds_Tick-ds.ds_Tick)*CLOCKS_PER_SEC/TICKS_PER_SECOND; +{ + struct EClockVal eval; + struct Device * TimerBase = DOSBase->dl_TimeReq->tr_node.io_Device; + UWORD freq = ReadEClock(&eval) / 1000; // 709 or 715 < 1024 + + ULONG difflo = eval.ev_lo - eval0.ev_lo; + ULONG diffhi = eval.ev_hi - eval0.ev_hi; + ULONG remhi = diffhi % freq; // max 10 bit + return difflo / freq + (((remhi << 22) / freq) << 10); }