Newsgroups: comp.os.msdos.djgpp From: manni DOT heumann AT gmx DOT de (Manni Heumann) Subject: RE: Accurate timing! References: X-Newsreader: News Xpress 2.01 Date: Fri, 18 Feb 2000 12:59:56 GMT NNTP-Posting-Host: dhcp33-226.uni-bielefeld.de Message-ID: <38ad4252$1_1@news.uni-bielefeld.de> X-Trace: 18 Feb 2000 14:00:02 +0200, dhcp33-226.uni-bielefeld.de Lines: 68 To: djgpp AT Delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article , djgpp AT delorie DOT com wrote: >If you have the Allegro game lib, it has timer interrupt routines. > >Otherwize you might be getting into re-programing the PIT chip. >Easy in real mode, but I dont know about protected. > >There might be somthing in the x2ftp ftp site. >ftp://x2ftp.oulu.fi/pub/msdos/programming > >Nigel Atkinson > I don't know, why I never tried to reprogram the PIT with a djgpp program, but now you gave me the idea. Thanks! So here is the output of the last 20 minutes. It won't work under windows, you should not try to access a floppy drive with the timer ticking faster, and your system time will be wrong afterwards. Otherwise it should be quite easy to use and shouldn't do any harm (but don't blame me if it does!). It will give you a timing accuracy of 1 ms. #include #include #include #include #include void Set_Timer() { outportb(0x43,0x36); outportb(0x40,0xa9); outportb(0x40,0x04); } void Reset_Timer() { outportb(0x43,0x36); outportb(0x40,0x0); outportb(0x40,0x0); } void Zero_Timer () { _farpokew (_dos_ds, 0x046c, 0); } unsigned int Read_Timer () { return _farpeekw (_dos_ds, 0x046c); } int main () { unsigned int start, stop; Set_Timer(); Zero_Timer(); start=Read_Timer(); getch(); stop = Read_Timer(); Reset_Timer(); printf ("start = %u, stop = %u, diff = %u\n", start, stop, stop-start); return 0; } -- Manni