Thread overview
Implementation of a delay() function
Jan 12, 2003
Catatonic Porpoise
Jan 12, 2003
Jeff Peil
Jan 19, 2003
Catatonic Porpoise
Jan 13, 2003
KarL
Jan 19, 2003
Catatonic Porpoise
Jan 20, 2003
KarL
Jan 21, 2003
rone
Re: Implementation of a delay() function 2
Dec 09, 2004
B.L. Gaino
Dec 11, 2006
Alfgaar
January 12, 2003
For a while, I have been writing programs in Borland Turbo C++ 3.0, and I had become used to its delay() function (defined in DOS.H, if I recall correctly), so I was distraught to learn that DMC++ does not contain one. This function takes one argument, the time to pause in milliseconds. I have tried to write such timer functions in the past, with very little success. Could anyone suggest a 'clean' and accurate way of implementing a delay() function similar to that of TC++?

Any help would be greatly appreciated. Except for the lack of delay(), which can hardly be called a fault, I have had only good experiences with DMC++ and plan to get the CD version in the near future.

Thanks,
Catatonic 'Graue' Porpoise

January 12, 2003
"Catatonic Porpoise" <graue@fojar.donotsendspam.com> wrote in message news:avr99b$b8j$2@digitaldaemon.com
> For a while, I have been writing programs in Borland Turbo C++ 3.0, and I had become used to its delay() function (defined in DOS.H, if I recall correctly), so I was distraught to learn that DMC++ does not contain one. This function takes one argument, the time to pause in milliseconds. I have tried to write such timer functions in the past, with very little success. Could anyone suggest a 'clean' and accurate way of implementing a delay() function similar to that of TC++?
>
> Any help would be greatly appreciated. Except for the lack of delay(), which can hardly be called a fault, I have had only good experiences with DMC++ and plan to get the CD version in the near future.
>
> Thanks,
> Catatonic 'Graue' Porpoise

#include <time.h>

int main()
{
    long nMillis = 10000;
    msleep(nMillis);
}



-- 
Jeff Peil


January 13, 2003
My personal way of doing "good" time/synchronisation on DOS-16 is to install a Interrupt driver on Int8 and reprogram the Timer to generate interrupt at a resolution close to the delay required and restore after using it.

This will make it more "hardware" oriented.

"Catatonic Porpoise" <graue@fojar.donotsendspam.com> wrote in message news:avr99b$b8j$2@digitaldaemon.com...
> For a while, I have been writing programs in Borland Turbo C++ 3.0, and I had become used to its delay() function (defined in DOS.H, if I recall correctly), so I was distraught to learn that DMC++ does not contain one. This function takes one argument, the time to pause in milliseconds. I have tried to write such timer functions in the past, with very little success. Could anyone suggest a 'clean' and accurate way of implementing a delay() function similar to that of TC++?
>
> Any help would be greatly appreciated. Except for the lack of delay(), which can hardly be called a fault, I have had only good experiences with DMC++ and plan to get the CD version in the near future.
>
> Thanks,
> Catatonic 'Graue' Porpoise
>


January 19, 2003
Jeff Peil wrote:
> #include <time.h>
> 
> int main()
> {
>     long nMillis = 10000;
>     msleep(nMillis);
> }

Thanks. I didn't expect it to be so convenient.

January 19, 2003
KarL wrote:
> My personal way of doing "good" time/synchronisation on
> DOS-16 is to install a Interrupt driver on Int8 and reprogram
> the Timer to generate interrupt at a resolution close to the
> delay required and restore after using it.
> 
> This will make it more "hardware" oriented.

Is this more accurate than functions such as msleep()? I unfortunately don't know the hardware well enough to do any of that.

-Catatonic 'Graue' Porpoise

January 20, 2003
"Catatonic Porpoise" <graue@fojar.donotsendspam.com> wrote in message news:b0djpo$2ekg$2@digitaldaemon.com...
> KarL wrote:
> > My personal way of doing "good" time/synchronisation on DOS-16 is to install a Interrupt driver on Int8 and reprogram the Timer to generate interrupt at a resolution close to the delay required and restore after using it.
> >
> > This will make it more "hardware" oriented.
>
> Is this more accurate than functions such as msleep()? I unfortunately don't know the hardware well enough to do any of that.

It is the "Resolutions" or "granularity" of the timer. I think you get about 55ms accuracy in DOS or Windows.

The documentations says:
------------------------------
void msleep(long milliseconds);
Description
Suspends execution of the program for the specified number of milliseconds. The
granularity depends on the operating system.




January 21, 2003

KarL wrote:

> "Catatonic Porpoise" <graue@fojar.donotsendspam.com> wrote in message
> news:b0djpo$2ekg$2@digitaldaemon.com...
>
>>KarL wrote:
>>
>>>My personal way of doing "good" time/synchronisation on
>>>DOS-16 is to install a Interrupt driver on Int8 and reprogram
>>>the Timer to generate interrupt at a resolution close to the
>>>delay required and restore after using it.
>>>
>>>This will make it more "hardware" oriented.
>>>
>>Is this more accurate than functions such as msleep()? I unfortunately
>>don't know the hardware well enough to do any of that.
>>
>
> It is the "Resolutions" or "granularity" of the timer. I think you get
> about 55ms accuracy in DOS or Windows.


right.
afaik on DM msleep is based on int 21h fc 2Ch dos function witch depend
on int 1ch interrupt witch depend on int 8 interrupt witch is ( supposed
to be ) called each 55ms by the i8254 0 timer.
it is possible to have a better resolution using int 15h function 86h
witch depend on the rtc MC146818 and have a resolution of 976 micosecond.
the best resolution is obtained using asm rdtsc instruction, supported
by DM.

roland



December 09, 2004
implementaion 2
I am not sure this works

int delay(int millisec)
{
clock_t timesec;

timesec = clock();

while((clock() - timesec) < millisec)
{
}

return millisec;

}


December 11, 2006
It works perfectly! Wonderfully!
Cool...
Yer great! :)