Solved

Timer for Borlandc C++

Posted on 1998-08-31
4
779 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

749 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