Pointer & GPC question..._(re)

Tue, 19 Aug 1997 10:52:45 +0200 (MEST)


According to Orlando Llanes:
> According to myself (Peter Gerwinski):
> > No way.
> Bummer :(

Well ... you can use the `/dev/mem' device to directly access memory,


    (* Linux lo-level file system access (here: memory access) *)

    Function mmap ( addr: Pointer; len: Word;
                    prot, flags, fd, off: Integer ): Word; C;

    (* In fact it returns a pointer.  But we convert it to Word. *)

    Function open ( filename: CString; Flags: Integer; ... ): Integer; C;


    Procedure InitTools;

    Var
      Dummy: Word;


    Function Allocate ( address, length: Word ): Pointer;

    Var
      segMem: Pointer;
      result: Word;

    begin (* Allocate *)
      segMem:= GetMem ( length + $FFF );
      if Word ( segMem ) and $FFF <> 0 then
        inc ( Word ( segMem ), $1000 - Word ( segMem ) and $FFF );
      if segMem = Nil then
        FatalError ( 'Linux drivers: cannot allocate video memory' );
      result:= mmap ( segMem, length, $03, $11, MemoryHandle, address );
      if Integer ( result ) <= 0 then
        FatalError ( 'Linux drivers: cannot mmap video memory' );
      Allocate:= Pointer ( result );
    end (* Allocate *);

    ...

    MemA0000:= Allocate ( $A0000, $10000 );


but then the program needs to be "suid root" to be executed.

(In fact this is how `svgalib' accesses video memory.)


> I plan to put it in the license where it's Copyrighted Freeware :)
> Hopefully it's what the LGPL stands for. I will release the source code,
> but I do want to retain the copyright, I won't charge for it's use tho.
        ^^(corrected)

That's what the LGPL stands for, *and* it allowes to link the library
with non-free software.  The ordinary GPL would stand for the same, too,
but would only allow to link the library with other free software.

> I saw it, but nothing about memory access,

It's a good example how to use existing GCC libraries from GPC.

> besides, I don't see why
> Borland's BGI should live on.

For compatibility's sake.  Nothing else.

Greetings,

    Peter

 Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
 maintainer GNU Pascal [970714] - http://home.pages.de/~gnu-pascal/ [970125]


Peter Gerwinski (peter@agnes.dida.physik.NO-SPAM-PLEASE.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es