From: michael DOT mauch AT gmx DOT de (Michael Mauch) Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie's problem with internal timer Date: Mon, 30 Mar 1998 04:16:53 +0200 Organization: Gerhard-Mercator-Universitaet -GH- Duisburg Lines: 60 Message-ID: <6fmvae$qgl$1@news-hrz.uni-duisburg.de> References: <6fjkln$spk AT bgtnsc02 DOT worldnet DOT att DOT net> NNTP-Posting-Host: ppp99.uni-duisburg.de Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On 28 Mar 1998 19:56:39 GMT, wrote: > I am a newbie to programming 32-bit DOS. I am used to programming 16-bit > DOS, and using memory locations 0000:046C-0000:046F to find the value of > the internal timer. However, when I make a program like this: > > #include > > void main(void) { > _farpeekl(0x0000,0x046C); > } > > I get a GP Fault when it is run. This is the output the error generates: You passed a wrong selector to _farpeekl(). Have a look at the libc reference for the _far* functions (type `info libc al _far*´ at the DOS prompt). It says among other things: | The first two groups of functions take a SELECTOR and an OFFSET. This | selector is *not* a dos segment. If you want to access dos memory, | pass _go32_info_block.selector_for_linear_memory (or just _dos_ds) as | the selector, and seg*16+ofs as the offset. #include #include int main(void) { long r = _farpeekl(_dos_ds,0x046C); printf("%d",r); return 0; } This does what you want. > How can I find the value of the internal timer without getting a GP Fault? > Can I still reprogram the timer frequency by writing to the 8253 control > register? Yes, you can, but it has been done for you already. Have a look at the libc function uclock(). You can get the sources for libc and look how it is done if you want. > I don't know if this is important: I am using RHIDE under Windows 95 to > compile the code It's not important where you compile your code, but it's important where you want to run your program. Win95 reprograms the timer chip every now and then, so uclock() has some problems there - and of course you will run into the same problems if you are trying to reprogram the timer chip inside Win95. But Win95 (and Win3.1) has a timing function that is accessible from DOS programs as well. I can send you sources for this (2KB), or you can try to find it in the mail archive by searching for "puclock". puclock() uses the Windows function in Win3.1 and Win95 and falls back to the original uclock() when your program is run in plain DOS. The granularity/accuracy is about 980 ns both in DOS and Windows, so there should be no need to roll your own. Regards... Michael