delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/16/01:02:23

From: "John M. Aldrich" <fighteer AT NO DOT SPAM DOT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Far pointers
Date: Tue, 15 Apr 1997 06:44:08 -0700
Organization: Two pounds of chaos and a pinch of salt
Lines: 44
Message-ID: <33538628.4156@NO.SPAM.cs.com>
References: <3352d8db DOT 6938055 AT news DOT earthlink DOT net>
NNTP-Posting-Host: ppp108.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Adam Haun wrote:
> 
> This may be a stupid newbie lamer question, but anyway...is it
> possible to use a far pointer in DJGPP without resorting to all those
> strange funtions referenced in the help file?

Depends on your definition of far pointers.  DJGPP programs do not need
far pointers in the traditional sense, because all code and data resides
in the same address space with an upper size limit of 4 GB.  You only
begin needing far pointers (or their cousins, near pointers) to access
addresses outside your program's data space, such as the VGA memory.  In
that case, there are at least three techniques that will work.

The simplest way to access an absolute address is as follows:

#include <sys/nearptr.h>
#include <string.h>

void poke_absolute_address( size_t addr, char byte, size_t length )
{
    __djgpp_nearptr_enable();
    memset( addr + __djgpp_conventional_base, byte, length );
    __djgpp_nearptr_disable();
    return;
}

Of course, this is both slow (in terms of the nearptr_enable and disable
functions) and unsafe (in that you can easily crash your computer with a
rogue address).  See chapters 10, 17 and 18 of the DJGPP FAQ
(v2/faq210b.zip) for more information.

-- 
John M. Aldrich <fighteer AT cs DOT com>                      

* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
  causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
  again.
* It doesn't necessarily do it in chronological order, though.
 
                                       --- Douglas Adams


- Raw text -


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