Because Free Pascal for dos is a 32 bit compiler, and uses a dos extender, accessing DOS memory isn’t trivial. What follows is an attempt to an explanation of how to access and use dos or real mode memory3.
In Protected Mode, memory is accessed through Selectors and Offsets. You can think of Selectors as the protected mode equivalents of segments.
In Free Pascal, a pointer is an offset 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:offset pair for it.
(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 function:
and then let this selector point to the physical memory you want using the function
Its length can be set using the 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 function:
More information on all this can be found in the Unit Reference, the chapter on the go32 unit.
3Thanks for the explanation to Thomas Schatzl (E-mail: tom_at_work@geocities.com)