Date: Thu, 12 Aug 1999 13:13:23 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: juergen AT peak-Service DOT com cc: djgpp AT delorie DOT com Subject: Re: How to convert a selector into a pointer? In-Reply-To: <37b19b34.33491353@NotesXnt> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Wed, 11 Aug 1999 juergen AT peak-Service DOT com wrote: > I transfer via DMA from a frame Grabber Card (BT848) to memory that > is allocated by __dpmi_allocate_dos_memory(). > This returns a DOS segment and a selector. > I want to port some image processing routines to DJGPP. These routines > use pointers to Bytes. > To mimimize the porting effort, i want to create a pointer which > points to the memory allocated by __dpmi_allocate_dos_memory() > and can be used by the image processing routines. Generally speaking, you can't. Moving data to and from the buffer allocated by __dpmi_allocate_dos_memory requires to use functions like dosmemget, dosmemput, _farpeekb, etc., since that buffer is not part of the ``normal'' data segment which you access from your C code. Accessing DOS memory requires to load a special selector into one of the CPU registers and instruct the CPU to use that selector instead of the usual data selector loaded into the DS register. The only way to access DOS memory with normal pointersis is to use the so-called ``near pointers'', see section 18.6 of the DJGPP FAQ list for details. But this technique effectively disables memory protection, and I don't recommend doing that, especially since you are messing with low-level stuff. Without memory protection, a single wild pointer can easily wipe out your hard disk--too high a price for portability, IMHO... You can always make your program more portable by defining a set of macros for referencing the DMA buffer, so that they expand into a simple pointer dereference with a 16-bit compiler, but into a function call with DJGPP. Alternatively, you could write your program in C++, where you can define a class that overloads the pointer dereference operator with a call to a suitable function.