I need help on counting milliseconds. I tried using a pointer to the system clock (I think), but it only counts ticks (1/18.2 seconds). I need real milliseconds.
And not a delay function like sleep().
It should work something like this:
int MilliSec=StopCount(); //Return number of milliseconds passed
Someone who can help?
I think this is another of these "depends on the compiler and OS" type answers.
With Win32 you can call GetLocalTime(), (or GetSystemTime() of course), in your StartCount, then again in your StopCount, and subtract the earlier time from the later time to give the elapsed time in millisecond.
The details of how you do this on other platforms I don't know, but the concept remains the same.
Forgot to mention. I'm using Borland 5.0 (DOS environment, not windows)
Is it possible (probably not recomended :) ) to use GetSystemTime() within DOS?
Perhaps someone else know another way?
Nope. It can be done under windows, but under DOS, you'd probably have to write it in ASM.
I'll check one of my ASM references, maybe I can cook something up.
Here's a program which does just this -- reporograms the timer to give millisecond accuracy.
Note!! This probably will only work in real, true, authentic DOS. Windows surely reprograms the timers, so it might barf on you if you mess with them.
> These routines reprogram the timer chip
Sounds dangerous... Anyway, I run this program from windows so I should probably not use this method :).
While speaking of DOS, what is the exact difference between DOS and console DOS? Is any DOS program run from windows a console DOS program? Or is it only those who "looks like" a console window? (like the "Hello World" programs)
I have been playing around with mode13 graphics for a while now, does that count as "real DOS" or console DOS?
All of this depends on the OS.
If you are in windows 95, 98, Me, you have 3 flavors:
1) Pure DOS -- you must shut down to a DOS prompt. This *is* DOS. It uses segment:offset addressing, DOS executables, and all DOS/BIOS functions are permitted. WinAPI obviously can't be used.
2) DOS under Windows -- executes in a command prompt, permits a lot of DOS commands not supported under console. Uses segment-offset addressing, uses DOS EXE file format, cannot use WinAPI commands, cannot use DOS/BIOS functions that will cause problems with Windows.
3) Console -- this is a windows program fully. It uses the windows PE file format, cannot run under pure DOS, can use all WinAPI commands, uses flat addressing, etc.
Note that, programmatically, 1 and 2 are the same -- they are DOS programs. The restrictions on 2) are imposed because it's executing under another operating system.
Under NT series operating systems (NT 4, 2000, XP) you only have a DOS emulator, so you can't use pure DOS. DOS under Windows is more restrictive than in 95/98 because of the emulator. The console is the same (although there are security considerations in NT4 or 2000 that you must worry about).
If you are using Mode13, you'd fall under type 2) -- it's truly a DOS program, being executed under Windows. Console programs are only allowed text modes, not graphical.
Thanks for the explanation (about DOS).
About the millisec-code you linked, will it work in Mode13 or will it cause problems with windows?
Anyway, thanks for your help :cool:
It would work IF you shut down to pure DOS (on a 95/98/Me machine).
It probably won't work if you run it under windows.