www.digitalmars.com         C & C++   DMDScript  

c++.dos.16-bits - Implementation of a delay() function

reply Catatonic Porpoise <graue fojar.donotsendspam.com> writes:
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
Jan 12 2003
next sibling parent reply "Jeff Peil" <jpeil bigfoot.com> writes:
"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
Jan 12 2003
parent Catatonic Porpoise <graue fojar.donotsendspam.com> writes:
Jeff Peil wrote:
 #include <time.h>
 
 int main()
 {
     long nMillis = 10000;
     msleep(nMillis);
 }
Thanks. I didn't expect it to be so convenient.
Jan 18 2003
prev sibling next sibling parent reply "KarL" <someone somewhere.org> writes:
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
Jan 12 2003
parent reply Catatonic Porpoise <graue fojar.donotsendspam.com> writes:
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
Jan 18 2003
parent reply "KarL" <someone somewhere.org> writes:
"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.
Jan 20 2003
parent rone <rone ronetech.com> writes:
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
Jan 21 2003
prev sibling parent reply B.L. Gaino <B.L._member pathlink.com> writes:
implementaion 2
I am not sure this works

int delay(int millisec)
{
clock_t timesec;

timesec = clock();

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

return millisec;

}
Dec 09 2004
parent Alfgaar <alfgaar msn.com> writes:
It works perfectly! Wonderfully!
Cool...
Yer great! :)
Dec 10 2006