From: Neil Goldberg Newsgroups: comp.os.msdos.djgpp Subject: Re: How to convert a selector into a pointer? Date: Wed, 11 Aug 1999 13:27:32 +0100 Organization: The MITRE Corporation Lines: 46 Message-ID: <37B16C34.10FE@mitre.org> References: <37b19b34 DOT 33491353 AT NotesXnt> NNTP-Posting-Host: mm58842-pc.mitre.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: top.mitre.org 934392322 24866 128.29.96.60 (11 Aug 1999 17:25:22 GMT) X-Complaints-To: usenet AT news DOT mitre DOT org NNTP-Posting-Date: 11 Aug 1999 17:25:22 GMT X-Mailer: Mozilla 3.04 (WinNT; I) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com juergen AT peak-Service DOT com wrote: > > Hello! > I've got the following problem: > I 'm a newbie to 32-Bit Dos-programming. > 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. Ah, my specialty, how to negotiate 32-bit DOS stuff using DJGPP. Okay, you've got your equivalent DOS segment, right? That's all you need (plus #include "sys/nearptr.h") To do what you want (use a 'Regular pointer'), we use the near pointer hack: __djgpp_nearptr_enable(); //somewhere in the beginning of main. Now, to get this magic pointer: char * magic_pointer = dos_segment * 16 + __djgpp_conventional_base; /*Segment is the DOS segment from alloc_dos_memory which is where the memory you allocated is, while conventional base overflows the pointer starting in the PROGRAM'S DATA SEGMENT around to linear memory 0 (where DOS memory is). From this point on, you can address that memory with magic_pointer*/ This technique is highly unportable and is the way to do the stuff that Watcom lets you do with pointers in 32-bit DOS mode that wouldn't be prudent in a gcc-based compiler. It effectively changes the segment limit of your program to 0xFFFFFFFF, so that all memory becomes addressable. It also lets you accidentally take down the computer if you're not careful, because you can corrupt any memory that would normally be protected from your program. So if your computer resets, its not my fault. Oh yeah, and do a __djgpp_nearptr_disable() at the end of your program to clean up. moogla