On 11/8/2023 11:40 AM, Bernd Böckmann via Freedos-devel wrote:
Hi all,

has anyone recently played around with the FreePascal 8086 cross compiler to generate DOS executables? I try to convert a near pointer to a far pointer while working under the small memory model, but that is not as trivial as it should be, because I have not found a language / library feature for it. For example, a cast operation does not work. But the semantics should be well defined (for the small memory model): set the segment part of the far pointer to DS.

I came up with the following solution, but I am wondering if I have overlooked something built-in?

function ToFarPointer(nearP: NearPointer) : FarPointer;
  var p: packed record ofs: NearPointer; segm: Word; end;
begin
  p.ofs := nearP;
  asm
    mov ax, seg @data
    mov [p.segm], ax
  end;
  ToFarPointer := FarPointer(p);
end;

(the above of course only works with the small / tiny / compact memory models)

Greetings, Bernd
How are you even working in the "small" memory model in FreePascal? One of the problems that I noticed when trying to use the 8086 version of FreePascal long time ago was that while someone went through the length of generating 8086 code, there was little compatibility with Turbo/Borland Pascal and actually DOS. "small" memory model means that you have a fixed code AND data segment, and all pointers are just offsets within those segments. Not having the definitions of NearPointer and FarPointer from the above snippet, one thing to consider is that when changing either CS or DS segments in a small memory model program, you need to make sure that you ALWAYS save and restore those segments when changing them temporarily...

I am pretty sure that the actual compatibility with the DOS environment has not significantly improved since I tried. And as in Pascal, by default you should not be messing with any pointers directly, any such feature to do so would be a very specific implementation/library issue...


Ralf





_______________________________________________
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel

Reply via email to