RetroBASIC

Retrogamecoding(.org) => Other Languages => Topic started by: Tomaaz on November 21, 2012, 12:39:15 am

Title: Pascal
Post by: Tomaaz on November 21, 2012, 12:39:15 am
Is it difficult for someone who knows BASIC, Lua and JavaScript to start with Pascal? How different is it? I think I learned it in the past but have forgotten everything totally. :) I'd like to try EGSL engine with Pascal.
Title: Re: Pascal
Post by: cvirus on November 21, 2012, 10:03:49 am
I don't think that is hard to move to pascal, see a simple record witch is very used in games.
But cybermonkey is the best person to answer that.


Code: [Select]
program Cars;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes
{ you can add units after this };
type
TCar = record
ModelName: string;
Engine: Single;
ModelYear: Integer;
end;
var
Car: TCar;
begin
Write('Input car Model Name: ');
Readln(Car.ModelName);
Write('Input car Engine size: ');
Readln(Car.Engine);
Write('Input car Model year: ');
Readln(Car.ModelYear);
Writeln;
Writeln('Car information: ');
Writeln('Model Name : ', Car.ModelName);
Writeln('Engine size : ', Car.Engine);
Writeln('Model Year : ', Car.ModelYear);
Write('Press enter key to close..');
Readln;
end.
Title: Re: Pascal
Post by: Cybermonkey on November 21, 2012, 10:49:36 am
If you know BASIC, Pascal is rather easy to learn. I learned Turbo Pascal in School but did not code for years. Then I did some programming in yabasic. After that I re-discovered Pascal. This time it was Freepascal. The only thing one has to take care of is the type safety of Pascal. All variables have to be declared before they are used the first time. See here: http://wiki.freepascal.org/Variables_and_Data_Types
BTW, if you want to use the egslengine with FPC I recommend not to use Lazarus. All pure Pascal programming is done with Geany by me.
Title: Re: Pascal
Post by: Tomaaz on November 21, 2012, 11:06:09 am
Declaring variables shouldn't be a problem. I did some coding in C, but, of course, I wouldn't call myself a C programmer. ;) I wasn't even thinking about Lazarus. The compiler is all I want to use. I will try and if I like it you can expect questions about Pascal and EGSL engine soon. ;)

Thanx!  :)
Title: Re: Pascal
Post by: Tomaaz on November 21, 2012, 04:35:01 pm
Forget it. I don't like Pascal. I could even stand annoying begin...end blocks (curly brackets are much better solution) but := instead of = is too much for me. :)
Title: Re: Pascal
Post by: Cybermonkey on November 21, 2012, 04:39:10 pm
Hm, in C you've got = and ==, so no big difference.
Title: Re: Pascal
Post by: Tomaaz on November 21, 2012, 04:46:48 pm
You can find '=' and '==' in many languages (probably all widely used today). Do you know other than Pascal languages that use ':=' and '='? I'm not saying that Pascal is bad language. I'm just afraid that constant switching between '=', '==' and ':=', '=' will be painful. ;)
Title: Re: Pascal
Post by: Bereb on November 24, 2012, 01:13:08 pm
I was fascinated by Pascal, as I was for Lisp too, for a long time, but these appear to me to be too complex languages (for my mind), so I left them at that : I prefer Basic(s), Logo, newLisp even though (because it's a very simple scripting Lisp/Scheme-like language) and Lua (because it's small but strong)  :) ... I'm just an amateur and I thank the ones who create programing or scripting languages within the reach of people like me  ;)
Title: Re: Pascal
Post by: Tomaaz on December 04, 2012, 04:30:18 pm
I didn't give up yet and tried to use egslengine with Free Pascal under Linux. Finally I was successful, but several errors occurred and I have to edit egslengine source code.

1. I had to remove everything related to Haiku from the source code, because compiler was trying to load all the stuff for Haiku
2. I had to fix two IF/THEN blocks

Background() and rectangle() commands still don't work, but I can use, for example, openwindow(), clearscreen(), dot(), box(), line(), wait(), sync(). I'm pretty sure I'm doing something wrong (the compiler has hundreds options), so hopefully someone will help me to make it work properly.

Title: Re: Pascal
Post by: Tomaaz on December 04, 2012, 07:07:31 pm
OK. There was something wrong with that file. I unpacked it once again and this time, there was no problem with IF/THEN blocks.  ??? It compiles with -Mdelphi option, but there is still this "Haiku" problem.
Title: Re: Pascal
Post by: Cybermonkey on December 04, 2012, 08:21:01 pm
Hm, weird. Works everything fine here. The Haiku stuff is only compiled if FPC detects Haiku ... Do you have the Vampyre Imaging Library added? Can you post the error output?
Title: Re: Pascal
Post by: Tomaaz on December 04, 2012, 08:26:24 pm
Code: [Select]
fpc test.pas -MDelphi (w katalogu /home/tomek)
Free Pascal Compiler version 2.4.0-2ubuntu1.10.04 [2011/06/17] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for i386
Compiling test.pas
Compiling egslengine.pas
Fatal: Can't find unit ImagingSDL used by egslengine
Fatal: Compilation aborted
Kompilacja nie powiodła się
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)

ImagingSDL seems to be used only under Haiku, but I might be wrong, of course.

BTW Background() was my mistake and I've just realized that rectangle() is not implemented yet (right?).

EDIT: It might be problem with that library, but on the other hand, I'm using EGSL without any problem on this machine, so I assume everything is installed.
Title: Re: Pascal
Post by: Cybermonkey on December 04, 2012, 09:10:50 pm
Nope, ImagingSDL is not SDL_Image (which is used on Haiku). You have to downlaod the Vampyre Imaging Library here: http://imaginglib.sourceforge.net/
Oh, and I recommend to use FPC 2.6.0 ...
Title: Re: Pascal
Post by: Tomaaz on December 04, 2012, 09:16:51 pm
Nope, ImagingSDL is not SDL_Image (which is used on Haiku). You have to downlaod the Vampyre Imaging Library here: http://imaginglib.sourceforge.net/

I did it, build it, but it doesn't work. :( Now I'm trying to install FreePascal 2.6.0...
Title: Re: Pascal
Post by: Tomaaz on December 04, 2012, 09:26:11 pm
FreePascal has been installed, but where should I place this library?  ???

EDIT All I'm getting is:
Code: [Select]
fpc test.pas -MDelphi (w katalogu /home/tomek)
Free Pascal Compiler version 2.6.0 [2011/12/23] for i386
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling test.pas
Compiling egslengine.pas
Fatal: Can't find unit ImagingSDL used by egslengine
Fatal: Compilation aborted
Kompilacja nie powiodła się
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)

:(
Title: Re: Pascal
Post by: Cybermonkey on December 04, 2012, 09:43:11 pm
Okay, I am doing it the crude way ... putting all necessary files from Vampyre into my working directory. Start with ImagingSDL.pas and you'll see what is missing. (Or better copy all files at once.)
Title: Re: Pascal
Post by: Tomaaz on December 04, 2012, 09:50:22 pm
I did it and now all I get is:
Code: [Select]
fpc test.pas -MDelphi (w katalogu /home/tomek/Test)
Free Pascal Compiler version 2.6.0 [2011/12/23] for i386
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling test.pas
test.pas(17,1) Warning: Library libopenjpeglinx86.a not found, Linking may fail !
Linking test
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: cannot find libopenjpeglinx86.a
Kompilacja nie powiodła się
test.pas(17,1) Error: Error while linking
test.pas(17,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)

Title: Re: Pascal
Post by: Aurel on December 04, 2012, 11:42:09 pm
Tomaaz ...
what you are trying to do ?    :o
Recompile EGSL source code to add your stuff ???   ;)
or fix something you don't like  ;D

I don't use linux ,and i am wondering is anyone else recompile egsl on windows maybe
just ask...
and don't worry i don't want change anything in egsl... ;D

good luck... :D
Title: Re: Pascal
Post by: Tomaaz on December 05, 2012, 01:21:13 am
Tomaaz ...
what you are trying to do ?    :o

I'm trying to use egslengine with FreePascal. Maybe Markus will waste his time and try to explain you what it means. I'm not gonna do it, because there is to big risk that you simply won't understand anything.

I don't use linux ,and i am wondering is anyone else recompile egsl on windows maybe

I didn't even touch EGSL source code. You've already showed me that you don't have an idea what machine code is. Now I can also see that you know absolutely nothing about Pascal and EGSL. So, there is a big question - why did you write your post? But you don't have to answer it. No one would understand your "poetry" anyway. Just please, do me a favour - don't start another pointless flame. Thanx.
Title: Re: Pascal
Post by: Cybermonkey on December 05, 2012, 08:31:08 am
Search for the file
Quote
libopenjpeglinx86.a
in the Vampyre directory and put it into your working directory, too.
Title: Re: Pascal
Post by: Tomaaz on December 05, 2012, 01:08:48 pm
I would if only... I could find it anywhere. ??? OK. How does it work under Windows? Do I need to copy manually all those files, too?

EDIT: If you've got all required files in one place, could you pack them and send me the archive? You're using Ubuntu so they might work on my Mint.
Title: Re: Pascal
Post by: Cybermonkey on December 05, 2012, 01:32:16 pm
It's the same on Windows. You even have to add more libraries.
It should be in Imaging/Extras/Extensions/J2KObjects
Oh, and I don't use Ubuntu anymore. I got now a 64 bit Mageia 2 installed on my new PC ...
Title: Re: Pascal
Post by: Tomaaz on December 05, 2012, 01:44:26 pm
It should be in Imaging/Extras/Extensions/J2KObjects

Yep. It finally works! Thanx a lot! :)

It's the same on Windows. You even have to add more libraries.

I hope Aurel will read this. ;)

Oh, and I don't use Ubuntu anymore. I got now a 64 bit Mageia 2 installed on my new PC ...

I heard this is a very nice distro. Support for Mint 9 I'm using at the moment is about to finished. I'm planning to stay with Mint, but who knows...? How is your experience with Mageia? Are you recommending it? No problems with running EGSL and BASICs (if you tried any of them)?
Title: Re: Pascal
Post by: Cybermonkey on December 05, 2012, 02:35:52 pm
No problems with EGSL. (Compiling is a bit more complicated because I switched to Lua 5.2 now and there are no suitable development libraries but it's also no problem to compile Lua yourself - with a little changed makefile).
I tried no BASIC on Magiea so far.
Title: Re: Pascal
Post by: Aurel on December 05, 2012, 06:45:57 pm
Quote
You've already showed me that you don't have an idea what machine code is.
You telling me this ...man who don't understand the difference between machine code
and assembler code ...hahah ;D
Please stop telling lies - :P
oh no...you became a liar...no ..no... :-X
Title: Re: Pascal
Post by: Tomaaz on December 05, 2012, 07:04:09 pm
Markus, FreePascal with egslengine rocks! :) Extremely easy to use and really fast. Together with Lua + EGSL it's a perfect team. ;)
Title: Re: Pascal
Post by: Cybermonkey on December 05, 2012, 08:29:14 pm
Glad, you like it.
Just a few hints: images, sounds, musics etc. are all plain pointers. Here an example:
Code: [Select]
var player:pointer;
..
player :=loadimage ('blabla.png');

Exceptions are bitmap fonts and animations; both are integers.
Title: Re: Pascal
Post by: Tomaaz on December 06, 2012, 07:11:27 pm
Thanx for information. :)

I got it working under Windows as well. All I needed to do was to replace libopenjpeglinx86.a with libopenjpegwin32.a (what was rather obvious) and add libcrtdll.a to the working directory. Source code of my Mandelbrot animation and a Windows executable are attached. The question is - how standalone is this executable? Will it work on any Windows machines or only on those with additional libraries (for example when EGSL is already installed)?
Title: Re: Pascal
Post by: Cybermonkey on December 06, 2012, 08:08:45 pm
It will need all required DLLs for distribution. Since I don't want to make chances to the System directory of Windows all DLLs are installed into the EGSL installation directory, so only EGSL itself has access to it. Either place all DLLs into System32 (or any appr. directories) or into the working directory of the mandelbrot file.
Title: Re: Pascal
Post by: Tomaaz on December 07, 2012, 02:01:47 am
That's what I thought. I guess it's not so easy on Linux...?
Title: Re: Pascal
Post by: Cybermonkey on December 07, 2012, 08:52:12 am
That's what I thought. I guess it's not so easy on Linux...?
Yes, on Linux all required libraries have to be installed on the destination computer (by the user).
There is however the possibility to deliver the libraries but it's rather complicated with using a shell script to start the application.
Title: Re: Pascal
Post by: Tomaaz on December 12, 2012, 11:36:21 am
That's probably the next thing I should learn more about, because at the moment I have no idea how could I show Linux examples to someone who doesn't have all required libraries installed. The easiest way is to show... Windows version (it works without problems under Wine), but...

What is the best Pascal forum? Is it that Lazarus one?
Title: Re: Pascal
Post by: Cybermonkey on December 12, 2012, 12:48:39 pm
What is the best Pascal forum? Is it that Lazarus one?
That depends. For game development I'd rather recommend www.pascalgamedevelopment.com/ (You can find me there with the nickname Cybermonkey  ;D)
I also ask/discuss on the Lazarus forum but not so much. Most other forums are very Delphi specific.
Title: Re: Pascal
Post by: Cybermonkey on December 13, 2012, 12:56:21 pm
For all of you who managed to compile egsl: why not try http://fpbascon.retrogamecoding.org/
It is possible to use all Pascal units with this little translator. (Put it just into you working directory).
Here's a little example:
Code: [Select]
IMPORT egslengine
DIM sprite AS pointer
MAIN
openwindow (640,480,32,"Sprite Test")
colourkey (255,0,255)
sprite = loadimage ("sprite.bmp")
putimage (200,200,sprite)
sync
inkey
closewindow
All keywords must be in uppercase but I recommend to use library functions in lowercase.
Title: Re: Pascal
Post by: Cybermonkey on December 13, 2012, 03:18:47 pm
Another one:
Code: [Select]
'ported from my old sdlgraph example

IMPORT egslengine

MAIN
openwindow (640,480,0,"S T A R S")
setframetimer (60)
backcolour (0,0,0)
DIM x [0 TO 500] AS integer
DIM y [0 TO 500] AS integer
DIM z [0 TO 500] AS integer
DIM i, key AS integer

FOR i=0 TO 500
  x[i]=INT (RND*screenwidth())+1
  y[i]=INT (RND*screenheight())+1
  z[i]=INT (RND*8)
NEXT

REPEAT
 clearscreen
  FOR i=0 TO 500
    x[i]=x[i]-z[i]
    IF x[i]<0 THEN
      x[i]=x[i]+screenwidth
    END IF
    colour (255,255,255)
    fillcircle (x[i],y[i],2)
  NEXT 
 
  colour (255,255,0)
  drawtext (INT(screenwidth/2),INT(screenheight/2)-7,"Stars")
  sync
 
  key=getkey
UNTIL key =27
closewindow

You can DIM a variable wherever you want (I hope so: it's alpha software)
Code: [Select]
IMPORT egslengine

MAIN
openwindow (300,200,0,"2D Drawing Test EGSL")
clearscreen
colour (0,0,255)
fillcircle (100,100,50)
colour (0,255,0)
fillbox (150,20,170,40)
colour (255,0,0)
DIM k AS INTEGER
FOR k = 1 TO 20
    line (10,10+k*8,200,0)
NEXT
colour (255,255,255)
drawtext (10,50,"Hello, this is a test")
redraw
inkey
closewindow
Title: Re: Pascal
Post by: Tomaaz on December 17, 2012, 11:39:01 pm
That's a bit to much for me. ;) Lua, Pascal, now BASIC... To be honest, after playing a lot with Lua and Pascal (which, surprisingly, I'm starting to like) I've lost interest in BASIC and, what is even more surprising, it seems... strange to me now (what the hell is NEXT...?  ;D ). :o
Title: Re: Pascal
Post by: Aurel on December 18, 2012, 06:50:02 am
...xHarbour,Haskel,Erlang.... ;D
Title: Re: Pascal
Post by: Tomaaz on December 20, 2012, 06:57:51 pm
Is it possible to modify egslengine, so it could work with sub-folders. I would like to create one sub-folder for all required libraries to not keep them together with my source codes and egsengine itself (it's a bit messy this way). I'm ready to do it by myself, but need some information and advice.
Title: Re: Pascal
Post by: Cybermonkey on December 20, 2012, 08:36:29 pm
Yes, you can add an include path to the compiler.
See the freepascal doc for further information: http://www.freepascal.org/docs-html/user/usersu7.html
Title: Re: Pascal
Post by: Tomaaz on December 20, 2012, 08:55:50 pm
Thanx! It was easier than I thought. :) I just placed egslengine and a new created folder with all required libraries to units folder in FPC directory and now it compiles from any location.