View Full Version : Program speed using time instead of memory

05-07-2002, 08:43 AM
Is there a way that I can make my programs run at a constant speed? It speeds up and slows down spontaneously. I am using Turbo C++ 1.00.

05-07-2002, 01:07 PM
There sure is, and I forget how.

05-08-2002, 09:56 AM
in time.h and dos.h there are some time functions, check them out.

Basically this is what you should do:

loop {
...get time...
...do stuff....
...get time 2...
...compare times...

now lets say you want your program to run at a constant speed...then every time you go through the loop, compare the two times which you get. Lets say you want your program to run at a certain FPS (like in graphics) constantly. Then you want to set a constant amount of time in which you refresh....lets say you refresh every 40 milliseconds...

then if "get time 2" was 40 milliseconds or greater than "get time", then you do stuff, otherwise you dont...

this will make it run pretty constant

05-09-2002, 08:33 AM
Does anybody know of a function in Turbo C++ 1.00 that can count time faster than a second? I looked through the functions in time.h and dos.h, but couldn't find anything.

This is mainly to make graphics run at a constant speed.

05-09-2002, 10:33 AM
Well, you could switch to djgpp+allegro, allegro has everything you could ever need for any kind of timing.

05-11-2002, 07:33 PM
To do that you are either going to have to hook the clock tick interrupt or mess around with the PIT. For information on PIT programming check out www.peroxide.dk. For information on hooking the clock tick interrupt, check out the RBIL.

NOTE: If the RBIL says do not hook the original timer interrupt then don't do it. If you do and forget to call the previous handler from your handler, your system time will be messed up. There is another interrupt that is also triggered every tick of the clock. This one is the one you should hook as it will not affect your system time.

05-13-2002, 08:27 AM
Peroxide.dk had no information about PIT that I could find, and I don't plan to switch to DJGPP. I tried to install it in the past, but all I did was waste 3 hours.