www.delorie.com/djgpp/faq/lowlevel/ioptr.html   search  
I want to call a DOS/BIOS function which requires a pointer to a buffer in ES:DI (or any other) register pair. How do I get the segment to put into the segment register?

If you use int86x() or intdosx() for a function supported by go32, then just put the address of your buffer into regs.x.di and forget about es. These functions are processed by go32, and it will take care of the rest.

If you call _go32_dpmi_simulate_int(), then you must put into that register pair an address of some buffer in conventional memory (in the first 1 MByte). If the size of that buffer doesn't have to be larger than the size of transfer buffer used by go32, then the easiest way is to use it. go32 doesn't assume the contents of that buffer to be preserved across function calls, so you can use it freely. That buffer is used by go32 for all DOS/BIOS services it supports, and it resides in conventional memory. go32 makes the address and the size of the transfer buffer available for you in the _go32_info_block external variable, which is documented the libcref.i Info file. Check the size of the buffer (usually, 4K bytes), and if it suits you, use its linear address this way:

dpmi_regs.x.di =
_go32_info_block.linear_address_of_transfer_buffer & 0x0f;
dpmi_regs.x.es =
(_go32_info_block.linear_address_of_transfer_buffer >> 4) & 0xffff;
If the size of the transfer buffer isn't enough, you will have to allocate your own buffer in conventional memory with a call to the _go32_dpmi_allocate_dos_memory() library function. It returns you the segment and offset directly in a structure pointed to by its argument. If you only need a small number of such buffers which can be allocated once, then you don't have to worry about freeing them: they will be freed by DOS when your program calls exit().

For bullet-proof code, you should test the size of the transfer buffer at runtime and act accordingly. This will be more important in djgpp v2.x, where that size can be dynamically changed.


  webmaster     delorie software   privacy  
  Copyright © 1995     Updated Feb 1995