Discussion:
HELP: beginner to pascal
(too old to reply)
d***@hotmail.com
2006-08-25 11:27:26 UTC
Permalink
I got hold of a friend's game written in Turbo Pascal 7. Am trying to
convert it to C using:

http://www.garret.ru/~knizhnik/pascal.html

I am a C/C++ programmer and know nothing about Pascal. I got hold of
Turbo Pascal 7 for DOS. When I try to use the Pascal to C convertor I
keep on getting "can't include file dos.pas & crt.pas". I assume these
are standard Turbo Pascal library files? But searching in my Turbo
Pascal folders there are no such files. Closest is windos.pas??

Please can someone help. If you want, I can link in the source code to
the game.
Riki Wiki
2006-08-26 06:44:25 UTC
Permalink
Hoi

You need to repost your message on the Borland news server to make
everybody see it and possibly answer your message.

How to post to Delphi newsgroups:
<http://delphi.wikia.com/wiki/Delphi_Newsgroups>
HubbleBubble
2006-08-29 12:51:46 UTC
Permalink
Post by d***@hotmail.com
I got hold of a friend's game written in Turbo Pascal 7. Am trying to
http://www.garret.ru/~knizhnik/pascal.html
I am a C/C++ programmer and know nothing about Pascal. I got hold of
Turbo Pascal 7 for DOS. When I try to use the Pascal to C convertor I
keep on getting "can't include file dos.pas & crt.pas". I assume these
are standard Turbo Pascal library files? But searching in my Turbo
Pascal folders there are no such files. Closest is windos.pas??
Please can someone help. If you want, I can link in the source code to
the game.
For a start both Pascal & C are very closely related they are both
Wirthian languages. If you understand C pascal should be easy because
it is typed in a fuller way - it's like C without the shorthand.
In C you have the block structure {
}
In Pascal you have begin
end;

There are some important differences:
There are slight differences is variable types and how they are
declared and the order parameters are pushed and popped from a call
frame stack.

In C you have include libraries eg stdio.h. In pascal this is achieved
with units. These are separately compiled routines. The difference
between this and a C library is that units often only contain the
public headings for procedures and functions - the source can be
hidden. The Dos unit handles things like file I/O and calling dos
functions whereas Crt handles keyboard and basic text screen stuff . If
you look at the source directory of TP you will see Dos.inc & Crt.inc -
these are listings of the public part of the units which will at least
make clear what they are trying to do. Because they were written by
Borland the source is hidden unless you have BP and then as stated by
others it may not be useful. The actual compiled units end in .tpu or
.tpp (if protected mode) but you can't disassemble them. Obviously it
is not possible for a cross translator to show routines where the
source is hidden. By examining the .inc files you should be able to
chooses equivalent C commands.from your own include libraries.
I had a similar problem as you but in reverse - there is a lot of good
C code around and I wanted to writre pascal equivalents. With just a
little study and a crib sheet of symbols I can now rewrite most C
routines to Pascal. :)
Jason Burgon
2006-08-29 14:15:05 UTC
Permalink
Post by HubbleBubble
For a start both Pascal & C are very closely related they are both
Wirthian languages.
Nicolaus Wirth would be turning in his grave (if he wern't still alive), if
he heard you saying that C is Wirthian language!
Post by HubbleBubble
If you understand C pascal should be easy [...]
True. Two other important differences are:

1). Pascal is strongly typed, like C++. This means that you can't generally
~implicitely~ cast apples into oranges. To do this you must ~explicitely~
tell the compiler that the cast is ok. E.g: P := Pointer(X);

2) There is a Boolean type explicitly defined in Pascal. This also ties in
to (1) in that you cannot implicitely cast an integer into a boolean like
you can in C. That means for example that all conditional branches ~must~
take an explicit boolean expression. Where in C you might have something
like:

int v;
{
.....
if (v)
{
....
}
}

This is not allowed in Pascal because "v" is not a boolean variable or a
boolean expression. Instead you need to explicitely generate a boolean
expression:

var v;
begin
.....
if v <> 0 then
begin
......
end;
end;

Note that the parenthesis are ~not~ required in the Pascal version.

One other mistake that many Pascal programmers make is to explicitely test
for True in pascal conditionals:

if SomeBoolValueOrExpression = True then
....

This is bad because it compares SomeBoolValueOrExpression to the exact
ordinal value of 1, which you should never do because although Ord(True) =
1, Pascal will treat any non-zero value as True (ie not False). So the
correct code for the above is simply:

if SomeBoolValueOrExpression then
....

or if you want its converse:

if not SomeBoolValueOrExpression then
....
--
Jason Burgon. Author of Graphic Vision
http://homepage.ntlworld.com/gvision
Jason Burgon
2006-08-29 14:19:39 UTC
Permalink
"Jason Burgon" <***@ntlworld.com> wrote in message news:JZXIg.17824$***@newsfe7-win.ntli.net...

[...]
Post by Jason Burgon
var v;
begin
.....
if v <> 0 then
begin
......
end;
end;
Oops, I missed off declaring 'v's type. I should have written:


var v: Integer;
begin
.....
if v <> 0 then
begin
......
end;
end;
--
Jason Burgon. Author of Graphic Vision
http://homepage.ntlworld.com/gvision
d***@hotmail.com
2006-08-30 10:11:47 UTC
Permalink
TP7 source code with embedded assembly:

http://members.lycos.co.uk/dhrubabandopadhyay/LITE_SRC.ZIP

Please see if you can get it to compile.
d***@hotmail.com
2006-08-30 08:38:16 UTC
Permalink
Okay, here is the full source code.

http://members.lycos.co.uk/doom2d/downloads/LITE_SRC.ZIP

See if you can get it to compile and run. It was originally built in
TP7. I think I need to run TP7 in VirtualPC/VMWare to be in real-DOS
mode. I tried using FreePascal, but that's 32-bit and don't think it
worked.

If there are anyone who knows assembly and can convert the assembly to
equivalent C/Pascal then that would be excellent!
d***@hotmail.com
2006-08-30 09:26:31 UTC
Permalink
Compiling this under native DOS TP7 I get:

Error 116: Must be in 8087 mode to compile this.
Post by d***@hotmail.com
Okay, here is the full source code.
http://members.lycos.co.uk/doom2d/downloads/LITE_SRC.ZIP
See if you can get it to compile and run. It was originally built in
TP7. I think I need to run TP7 in VirtualPC/VMWare to be in real-DOS
mode. I tried using FreePascal, but that's 32-bit and don't think it
worked.
If there are anyone who knows assembly and can convert the assembly to
equivalent C/Pascal then that would be excellent!
Jonas Maebe
2006-08-30 11:09:04 UTC
Permalink
Post by d***@hotmail.com
Error 116: Must be in 8087 mode to compile this.
Then turn on 8087/80287 mode in the compiler options.


Jonas
d***@hotmail.com
2006-08-31 11:06:17 UTC
Permalink
http://members.lycos.co.uk/dhrubabandopadhyay/LITE_SRC.ZIP

Excellent! It fully compiles and runs.

ml /c liteasm.asm
tpc /b lite2 /$N+

Though it looks frozen when the game starts. Am not sure whether that's
a game logic thing, or whether the liteasm.asm file was compiled with
masm 32-bit.
d***@hotmail.com
2006-08-31 11:22:26 UTC
Permalink
Does the assembly file have to be compiled with a 16-bit assembler if
wanting to use with 16-bit pascal?
Jonas Maebe
2006-08-31 11:37:40 UTC
Permalink
Post by d***@hotmail.com
Does the assembly file have to be compiled with a 16-bit assembler if
wanting to use with 16-bit pascal?
It has to be compiled for 16 bit real mode. I don't know whether 32 bit
masm's still support that.


Jonas

Loading...