delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/05/00:31:15

Date: Sat, 01 Oct 1994 10:09:52 +0100
From: Thomas DOT Sams AT nbi DOT dk
Subject: Re: accuracy of clock()
Sender: Thomas Sams <SAMS AT nbivax DOT nbi DOT dk>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Cc: SAMS AT nbivax DOT nbi DOT dk

Return-path: <cnc AT netcom DOT com>
Received: from netcom8.netcom.com by nbivax.nbi.dk (PMDF V4.2-13 #5783)
 id <01H88AR6Q7WWAM3R8Y AT nbivax DOT nbi DOT dk>; Fri, 28 Jan 1994 21:14:03 +0100
Received: from localhost by netcom8.netcom.com (8.6.4/SMI-4.1/Netcom)
 id MAA03592; Fri, 28 Jan 1994 12:14:09 -0800
Date: Fri, 28 Jan 1994 12:14:05 -0800 (PST)
From: cnc AT netcom8 DOT netcom DOT com (Christopher Christensen)
Subject: RE: How to measure time better than 1/10000 sec?
In-reply-to: Thomas Sams <SAMS AT nbivax DOT nbi DOT dk>
 "How to measure time better than 1/10000 sec?" (Jan 28,  3:22pm)

Here is an old post I received some time ago. 
    Thomas Sams.

You can read the timer register directly.  The following code should work
assuming that the timer hasn't been reprogrammed to interrupt at more than
18.2 Hz.  The timer runs at 1193180 Hz (65536 times faster than the 18.2
Hz timer tick).  If you have problems with this code, let me know and I will
try to fix it.

------------------------------------------------------------
/* short timer16() -- return 16-bit timer value */
/* timer resolution is 0.8381 microseconds (1193180 Hz clock) */
/* rolls over 18.2 times per second */
	.align 2
.globl  _timer16
_timer16:
	cli
	movb  $0xc2,%al       # read back cmd (status+count)
	outb  %al,$0x43
	.byte 0xeb,0          # jmp delay
	inb   $0x40,%al       # get status (msb=out pin)
	movb  %al,%cl
	.byte 0xeb,0          # jmp delay
	inb   $0x40,%al       # get LSB
	movb  %al,%ah
	.byte 0xeb,0          # jmp delay
	inb   $0x40,%al       # get MSB
	sti
	xchgb %ah,%al
	orw   %ax,%ax
	jz     _timer16       # zero is problematic
	shlb  $1,%cl          # carry=out status
	rcrw  $1,%ax
	negw  %ax
	ret


/* unsigned int timer32() -- return 32-bit timer value */
/* returns a timer with 0.8381 microsecond resolution that rolls over
   about once an hour */
	.align 2
.globl  _timer32
_timer32:
	call  __go32_conventional_mem_selector
	movw  %ax,%gs
	xorl  %eax,%eax
	movl  %gs:0x046c,%edx   # read timer tick count in dos memory
	call  _timer16
	cmpl  %gs:0x046c,%edx   # has timer advanced?
	je    Ldone4

	testb $0x80,%ah   # if msbit==0 inc %edx
	jnz   Ldone4
	incl  %edx
Ldone4:
	shll  $16,%edx
	orl   %edx,%eax
	ret
------------------------------------------------------------


-- 
----------------------------------------------------------------------
:  Christopher  :  Huntington Beach California, USA                  :
:  Christensen  :  email:  cnc AT netcom DOT com                            :
----------------------------------------------------------------------

- Raw text -


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