Solved

Timer for Borlandc C++

Posted on 1998-08-31
4
772 Views
Last Modified: 2010-04-02
Hi everyone, I am using Borland C++ version 3.1 and I need to implement a timer that interrupts the program execution at defined intervals. The only timer commands in Borland C++ is a stopwatch and a command to fetch the system time. Does anyone have any ideas of getting a timer running to interrupt my program that will be doing lots of other things? Thanks
0
Comment
Question by:rose337
  • 3
4 Comments
 
LVL 2

Expert Comment

by:warmcat
ID: 1171651
Rosie,

If yours is a Windows app, you can use ::SetTimer() and ::KillTimer() (Win16 and Win32 API calls) to request that a window be sent periodic WM_TIMER messages.

If it's a DOS app, you can hook the system 18Hz 'clock tick' interrupt 0008.

If it's a console app, then the 'multimedia timer' is your man: look in the docs for ::timeSetEvent().  It does not need a window handle to do the deed, and takes a pointer callback function which is executed periodically.

An alternative methodology, if your program has an ''outer loop'' of some sort, is to check ::GetTickCount() at the top of your loop, and execute your periodic code after more than a certain number of ticks (==mS) have elapsed.

Regards,

-Andy
0
 

Author Comment

by:rose337
ID: 1171652
Thanks Andy, but that would work only for Visual C++. I am now in Borland C++ version 3.1. This is a dos based compiler and it is very old. The time functions are different as described above.
0
 
LVL 2

Accepted Solution

by:
warmcat earned 100 total points
ID: 1171653
> If it's a DOS app, you can hook the system 18Hz
> 'clock tick' interrupt 0008.

This is nothing to do with Windows: it is a periodic interrupt that goes all the way back to the very first PC.  It occurs at 18.2Hz, and you can hook it at 0000:0020...0000:0023.

Be sure to use a _asm CLI instruction before fiddling with it, and a _asm STI instruction after you have hooked it.  The contents of 0000:0020 is a far * to the interrupt routine, in (low-offset)(high-offset)(low-seg)(high-seg) form.

Your interrupt routine should JMP to the original address that was at 0000:0020 after doing its stuff.

Be aware that while in an Interrupt Service Routine, it is quite dodgy to use any DOS functions, as DOS was not designed to be reentrant.

-Andy
0
 
LVL 2

Expert Comment

by:warmcat
ID: 1171654
BTW, 0000:046C contains a 32-bit count of the clock ticks, maintained by DOS.  So, for example:

unsigned long RoseGet18HzTickCount()
{
   unsigned long * pul=(unsigned long *)0x0000046c;
   return (*pul);
}

would allow you to use the polling technique I initially outlined with 0.055S resolution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now