delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/29/17:25:07

Date: Sun, 29 Mar 1998 14:23:30 -0800 (PST)
Message-Id: <199803292223.OAA18975@adit.ap.net>
Mime-Version: 1.0
To: <OneClickAway AT worldnet DOT att DOT net>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Newbie's problem with internal timer

At 07:56  3/28/1998 GMT, OneClickAway AT worldnet DOT att DOT net 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 <sys/farptr.h>
>
>void main(void) {
>   _farpeekl(0x0000,0x046C);
>}
>
>I get a GP Fault when it is run.  This is the output the error generates:
[stricken]

Read more carefully the documentation of `_farpeekl'. That first argument is
not a real-mode segment, but a protected-mode *selector*. The selector with
value 0 is the null selector and is always invalid, hence the crash. You
need a selector which addresses DOS memory, and conveniently one exists in
the `_dos_ds' macro. The offset argument, on the other hand, is a linear
offset. You can construct it from a real-mode style seg:ofs address with
((seg << 4) + ofs).

So what you want is:

#include <sys/farptr.h>
#include <go32.h>

_farpeekl(_dos_ds, 0x0046C);


Also, `main' must return an `int', 0 for success.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019