Board index » delphi » A couple quick questions invloving GNU Pascal: Books, Accessing memory and Ports

A couple quick questions invloving GNU Pascal: Books, Accessing memory and Ports

Hello everyone,
I realize this is a very stupid question and that it should be
painfully obvious, but I cannot seem to find the answer.  Basically, I
recently started programming in the DJGPP-GPC enviornment and have
been able to do alot the of the basic stuff, I am very familiar with
Turbo Pascal.  Unfortunentally, I am not familiar with the other
languages that the compiler is based on (ansi, extended etc.) and an
not familiar with protected mode.  I was wondering if there are any
good books/docs etc on the subject.

Also, I have been trying to find out about how to write, say a byte,
directly to memory or to read a byte directly from memory.

ie

var
  P : ^void;

begin
  .
  .
  .
  GetMem(P, The_Space_I_Need);
  P := $A0000;                                      {Video Memory}
  .
  .
  .
end.

  Now how do I read the and write to the memory I have allocated.  In
Turbo Pascal, i could use the mem[segment:offset] array, but that is
not available in GNU Pascal...  

  I also wish to be able to read and write to ports, of the material I
have found, I know that the port[] array that was in Turbo Pascal is
also no longer available.  What can I do in its place (ie writing to
SB registers and to the Palette registers)

Any help on any of the above problems would be of a huge help!

Thanks in advance
-Brin

                           "I am therefore I think"
*******************************************************************************
*SUBSCRIBE!: If you're not on then get signed up!                    *
*     >>>>>Send an EMail to:  b...@star.net<<<<<                  *
*     leaving the body blank and Subscribe in the Subject.          *
* DISTRIBUTE!: Send this to all your friends, enemies, and        *
*     to Samantha (I wonder if she reads this)...                           *
*COME AND SEE:The archives                                              *
*     http://www.star.net/people/~brin                                        *
* CONTRIBUTE!: Send me funny stuff.                                     *
***************************************************************************

 

Re:A couple quick questions invloving GNU Pascal: Books, Accessing memory and Ports


Quote
Brin (b...@star.net) wrote:
> [...]  Unfortunentally, I am not familiar with the other
> languages that the compiler is based on (ansi, extended etc.)

Look into the Info documentation, also available online at
http://agnes.dida.physik.uni-essen.de/~gnu-pascal/gpc-doc.html,
into the chapters "From Borland Pascal to GNU Pascal" and
"GNU Pascal Extensions - Extensions to ISO-7185 Pascal language"
and "About Pascal and Extended Pascal languages - A comparision
of Borland Turbo Pascal with Extended Pascal" (in this order,
because the second and third are a little outdated).

Quote
> [...] I was wondering if there are any
> good books/docs etc on the subject.

Not yet, but be invited to join us in writing a book and/or
improving the existing documentation. ;-)

Quote
> Also, I have been trying to find out about how to write, say a byte,
> directly to memory or to read a byte directly from memory.

That's not so easy in protected mode ... look into the DJGPP
drivers of BO5 for code involving inline assembly to solve
this task.  (BO5 is located in the contrib subdirectory of the
GNU Pascal distribution at ftp://kampi.hut.fi/jtv/gnu-pascal/.)

(* More about this was already posted to the GNU Pascal mailing list. *)

Hope this helps,

    Peter
    <peter.gerwin...@uni-essen.de>

Re:A couple quick questions invloving GNU Pascal: Books, Accessing memory and Ports


I have almost the same problem.GNU pascal is supposed to be compatible
with Turbo pascal;
What happens if I say
....
program foo;
uses crt;  <---legal in TP & BP ;GNU ???
.....
and another thingy: TP & BP don't make OBJ's,the linking is automatic.Is
this a feature of Pascal or just the borland products?I mean,will GNU
pascal produce any .O's ?Can I link GNU Pascal code in GCC progs?
Just curios..

--
tudor 'at' cam 'dot' org
yoda69 'at' hotmail 'dot' com
http://www.cam.org/~tudor

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d-(--) s(-):(+) a? C+ UL>++++ P L>+++++ E- W++ N o K---(----) w---
O---- M-- V-? PS+++ PE Y PGP t+ 5-- X+++>++++ R tv b+ DI D+ G e->++
h>++ r- y>+++++
------END GEEK CODE BLOCK------

Re:A couple quick questions invloving GNU Pascal: Books, Accessing memory and Ports


Tudor <tu...@cam.org> was overheard mumbling incoherently about Re: A
couple quick questions invloving GNU Pascal: Books, Accessing memory
and Ports:

Quote
>I have almost the same problem.GNU pascal is supposed to be compatible
>with Turbo pascal;
>What happens if I say
>....
>program foo;
>uses crt;  <---legal in TP & BP ;GNU ???
>.....

GPC supports the uses statement, but AFAIK, the crt unit hasn't been
ported.

Quote
>and another thingy: TP & BP don't make OBJ's,the linking is automatic.Is
>this a feature of Pascal or just the borland products?I mean,will GNU
>pascal produce any .O's ?Can I link GNU Pascal code in GCC progs?
>Just curios..

GPC works just like gcc.  You can do
gpc foo.pas -o foo.exe  -> produces foo.exe, no .o
gpc -c foo.pas          -> produces foo.o

You can call c functions from pascal, as long as you give it a
prototype:
function my_c_func(x:integer):integer;c;
I haven't tried the other way around.
     __                         __
 /> /_ /| /   /\  /|  />  /| / /_ /  /
/> /_ / |/   /_/ /-| / \ / |/ /_ /_ /_
http://users.vnet.net/bdarnell
bdarn...@vnet.net

Re:A couple quick questions invloving GNU Pascal: Books, Accessing memory and Ports


Quote
On Tue, 07 Jan 1997 17:29:29 -0800, Tudor <tu...@cam.org> wrote:
>I have almost the same problem.GNU pascal is supposed to be compatible
>with Turbo pascal;

No, you are wrong here.
GNU Pascal doesn't claim to be a drop-in replacement for Turbo Pascal.
It is designed to be a portable compiler, running on a variety of
hardware and operating systems. Although it accepts a large subset of
the Borland Pascal syntax, it (currently) doesn't come with the units
you are familiar with.
Some things which are legal in Borland Pascal (direct memory access)
are not portable at all and will probably never appear in GNU Pascal.

Quote
>What happens if I say
>....
>program foo;
>uses crt;  <---legal in TP & BP ;GNU ???
>.....

The construction is perfectly legal, as long as you provide a CRT
unit. ;-)
No, serious: work is being done to write some borland replacement
units. A BGI replacement for djgpp already exists. We still need
volunteers.

Quote
>and another thingy: TP & BP don't make OBJ's,the linking is automatic.Is
>this a feature of Pascal or just the borland products?I mean,will GNU
>pascal produce any .O's ?

Yes.
Or assembly, if you prefer that....
If you invoke it with the --automake switch it will automatically
build units if necessary (like Borland does)

Quote
> Can I link GNU Pascal code in GCC progs?

If you mean GCC object code and libraries: yes.
Simply declare them as "external; C". That's all.

Quote
>Just curios..

Hope this helped,

JanJaap
--
"Nothing shocks me, I'm a scientist", Indiana Jones

Re:A couple quick questions invloving GNU Pascal: Books, Accessing memory and Ports


Quote
> program foo;
> uses crt;  <---legal in TP & BP ;GNU ???

Parts of CRT are ported in a library `BO5'.  Check the
`contrib' subdirectory of the GNU Pascal distribution at
ftp://kampi.hut.fi/jtv/gnu-pascal/.  From the BO5 file
`djgpp.icl' you can also learn about direct memory access etc.

It should not be too difficult to write a CRT Unit for
GNU Pascal using the stuff already in BO5.  Any volunteer
out there?

Quote
> and another thingy: TP & BP don't make OBJ's,the linking is automatic.Is
> this a feature of Pascal or just the borland products?

It is a *mis*feature of Borland Pascal that it cannot produce `.obj'
files and thus you cannot access functions written in Borland Pascal,
say, from Borland C.  However automatic linking *is* a feature of
Borland Pascal; use the commmand-line option `--automake' to get this
with GNU Pascal.

Quote
> Can I link GNU Pascal code in GCC progs?

Yes.  Just take care of the Capitalization Of The First Letter In
Each External Pascal Identifier.  E.g., if you have a Unit

    Unit Foo;

    Interface

    Function FooBar ( Var Bar: Integer ): Boolean;

    Implementation

       (* ... ! *)

    end.

then you can use the Function `FooBar' from C using the following
header `foo.h':

    #define BOOLEAN char

    extern BOOLEAN Foobar ( int *bar );

Note that this does not only work on DOS (with DJGPP or EMX) but
on *any* platform supported by GNU Pascal.

Hope this helps,

    Peter

      e-mail:  peter.gerwin...@uni-essen.de
home address:  D\"usseldorfer Str. 35, 45145 Essen, Germany
         WWW:  http://agnes.dida.physik.uni-essen.de/~peter/

Other Threads