In Proteced Mode, memory is accessed through Selectors and O sets. You can think of Selectors as the protected mode equivalents of segments.
In Free Pascal, a pointer is an o set into the DS selector, which points to the Data of your program.
To access the (real mode) dos memory, somehow you need a selector that points to the dos memory. The go32 unit provides you with such a selector: The DosMemSelector variable, as it is conveniently called.
You can also allocate memory in dos's memory space, using the global_dos_alloc function of the go32 unit. This function will allocate memory in a place where dos sees it.
As an example, here is a function that returns memory in real mode dos and returns a selector:o set pair for it.
procedure dosalloc(var selector : word;
var segment : word; size : longint); var result : longint; begin result := global_dos_alloc(size); selector := word(result); segment := word(result shr 16); end; |
(You need to free this memory using the global_dos_free function.)
You can access any place in memory using a selector. You can get a selector using the allocate_ldt_descriptor function, and then let this selector point to the physical memory you want using the set_segment_base_address function, and set its length using set_segment_limit function. You can manipulate the memory pointed to by the selector using the functions of the GO32 unit. For instance with the seg_fillchar function. After using the selector, you must free it again using the free_ldt_selector function.
More information on all this can be found in the Unit reference, the chapter on the go32 unit.