Mail Archives: djgpp/1999/08/12/06:56:38
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
- Raw text -