delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/19/05:48:37

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: rawclock() bug, not just in docs
Date: Mon, 18 Aug 1997 17:26:52 -0400
Organization: Cornell University http://www.cornell.edu
Lines: 59
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <33F8BE1C.19DF@cornell.edu>
References: <33F8AAC0 DOT 2114 AT geocities DOT nospam DOT com>
Reply-To: asu1 AT cornell DOT edu
NNTP-Posting-Host: cu-dialup-0025.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Mark Slagell wrote:

> It must be simply taking the system's ticks since midnight at first 
> call and subtracting that with each subsequent call, I guess that 
> would explain it.  This is hard to work around because reading ticks 
> via __dpmi_int() or int86() causes the date not to advance at 
> midnight, at least on my machine.

here is the source to rawclock:

/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <go32.h>
#include <libc/farptrgs.h>

unsigned long
rawclock(void)
{
  static unsigned long base = 0;
  unsigned long rv;
  rv = _farpeekl(_dos_ds, 0x46c);
  if (base == 0)
    base = rv;
  return rv - base;
}

you seem to be right about this. if the counter at 0x46c resets at
midnight, you will get erronous results. one workaround might be to do
the following:

unsigned long
rawclock(void)
{
  static unsigned long base = 0;
  unsigned long rv;
  rv = _farpeekl(_dos_ds, 0x46c);
  if (base == 0)
    base = rv;
  if( rv < base )   /* see if the counter has reset */
  {
    rv += ULONG_MAX - base; /* adjust ticks elapsed */
    base = rv - (ULONG_MAX - base);  /* adjust base */
  }

  return rv - base;
}

would this be acceptable?
-- 
   Sinan
 
*******************************************************************
 A. Sinan Unur                                WWWWWW
                                              |--O+O
 mailto:sinan DOT unur AT cornell DOT edu                C   ^ 
 http://www.people.cornell.edu/pages/asu1/     \  ~/ 

Unsolicited e-mail is _not_ welcome, and will be billed for.
*******************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019