Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Timer for Borlandc C++

Posted on 1998-08-31
4
Medium Priority
?
793 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 300 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

598 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