Article View: net.micro.pc
Article #7256Re: Sleep(milliseconds) Help Sought
From: bc
Date: Tue, 15 Jul 1986 00:39
Date: Tue, 15 Jul 1986 00:39
77 lines
2588 bytes
2588 bytes
> I am trying to develope a sleep() function under Latice C that
> takes an argument in milliseconds. I tried BIOS interupt
> 15 function 86, with no luck. Any and all help will be greatly
> appreciated.
> --
> Bryan Costales, EEG Systems Laboratory
The following works (I use Lattice 2.15 still) in tenths of a second.
Presumably, the factor could be changed to from 1.82 to 182. to get
milliseconds, but I would watch out for the overhead of the functions
themselves, especially since I have dragged in the floating point divide.
I expanded the register union from a header file from memory. I hope I
got it right.
------------------------------ cut here ---------------------------------
static union
{
struct
{
unsigned ax;
unsigned bx;
unsigned cx;
unsigned dx;
unsigned si;
unsigned di;
} x;
struct
{
char al;
char ah;
char bl;
char bh;
char cl;
char ch;
char dl;
char dh;
} h;
} regs;
#define TIME_OF_DAY 0x1A
/* ---------------------------------------------------------------------
now obtains the value of the tick counter expressed as a long in
tenths of a second.
---------------------------------------------------------------------
*/
long
now ()
{
regs.x.ax = 0;
int86 (TIME_OF_DAY, ®s, ®s);
return (long) ((((long) regs.x.cx << 16) | (long) regs.x.dx) / 1.82);
}
/* ---------------------------------------------------------------------
sleep causes the program to be put to sleep (to pause) for the given
period, expressed in tenths of a second.
---------------------------------------------------------------------
*/
sleep (dur)
unsigned dur;
{
long time, now();
time = now();
while (now() - time < (long) dur)
;
}
--
bc Bill Crews @ NetCor Data International, Inc
..!{seismo,gatech,ihnp4}!ut-sally!cyb-eng!bc (512) 835-2266
Technical Details
Message-ID:
<915@cyb-eng.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utcs!mnetor!seismo!ut-sally!cyb-eng!bcReferences:
<128@eeg.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!utcs!mnetor!seismo!ut-sally!cyb-eng!bc From: bc@cyb-eng.UUCP Newsgroups: net.micro.pc Subject: Re: Sleep(milliseconds) Help Sought Message-ID: <915@cyb-eng.UUCP> Date: Mon, 14-Jul-86 20:39:36 EDT Article-I.D.: cyb-eng.915 Posted: Mon Jul 14 20:39:36 1986 Date-Received: Tue, 15-Jul-86 01:38:46 EDT References: <128@eeg.UUCP> Distribution: na Organization: Cyb Systems, Austin, TX Lines: 77