[prev] [prev-tail] [tail] [up]

### 8.5 Using D O S memory under the Go32 extender

Because Free Pascal for D O S is a 32 bit compiler, and uses a D O S extender, accessing DOS memory isn’t trivial. What follows is an attempt to an explanation of how to access and use D O S or real mode memory4.

In Proteced 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) D O S memory, somehow you need a selector that points to the D O S memory. The go32 unit provides you with such a selector: The DosMemSelector variable, as it is conveniently called.

You can also allocate memory in D O S’s memory space, using the global_dos_alloc function of the go32 unit. This function will allocate memory in a place where D O S sees it.

As an example, here is a function that returns memory in real mode D O S and returns a selector:offset 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.

[prev] [prev-tail] [front] [up]