Recent

Author Topic: Compile a very old Pascal Source with FPC  (Read 10444 times)

toaopeter

  • Newbie
  • Posts: 4
Compile a very old Pascal Source with FPC
« on: September 17, 2018, 06:44:41 pm »
Good evening from Germany,

for historic reasons I would like to keep a very old chess program (published in Byte Magazin in 1978 by the computer chess pioneers Peter W. Frey and Larry Atkin) and compile it for recent hardware like ARM.

Originally the source was written in a Pascal version for mainframe computers.
However, I do have a modified version that compiles 100% with the GNU Pascal compiler, but not Free Pascal. (I attached the historic source code to this post. )

Unfortunately I am no Pascal expert and I don't know if there is any way to compile it with FPC so we could create binaries for Raspberry Pi and other newer hardware.

Maybe you guys can help!?

Peter

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Compile a very old Pascal Source with FPC
« Reply #1 on: September 17, 2018, 08:36:54 pm »
The problem is that GPC accepts a lot of Cisms. It usually is smarter to use the original, pre-GPC source to start with, since quite often adapting it to GPC takes it further away from mainline Pascal.

That said if you replace C string delimiter  " " with normal Pascal delimiter ' ' and compile with -Miso, then it compiles ?
« Last Edit: September 17, 2018, 08:39:42 pm by marcov »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Compile a very old Pascal Source with FPC
« Reply #2 on: September 17, 2018, 09:00:58 pm »
the bigger problem are gotos across different procedures

good old goto style approach.


this did the trick (after replacing " with '):
Code: Pascal  [Select][+][-]
  1. {$mode iso}
  2. {$modeswitch nonlocalgoto}
  3.  
  4. PROGRAM chess2(INPUT,OUTPUT);
It compiled!
...and fails in run-time...
« Last Edit: September 17, 2018, 10:13:19 pm by skalogryz »

toaopeter

  • Newbie
  • Posts: 4
Re: Compile a very old Pascal Source with FPC
« Reply #3 on: September 19, 2018, 06:04:18 pm »
This is really weird. YES, it compiles!

Can confirm this. At least a step forward.

But why the heck .. "error in format of program" Hmm..


Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Compile a very old Pascal Source with FPC
« Reply #4 on: September 19, 2018, 07:20:06 pm »
It runs... but can any of you give me some valid first move input? I believe it asks twice for "from" and "to", but I'm not so knowledgeable in chess to know this. With that given, I might be able to find out what's wrong.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Compile a very old Pascal Source with FPC
« Reply #5 on: September 19, 2018, 08:14:25 pm »
The Highlighter used in Lazaus IDE does not like the source.
After applying the change sproposed by skalogryz, the highlighter thinks that everything after
Code: Pascal  [Select][+][-]
  1. BEGIN
  2.   FOR INTY := ZY DOWNTO AY DO          (* LOOP THRU BIT BOARD WOROS *)
  3.     IF A.RSTI[INTY] <> 0 THEN
  4.     BEGIN

in FUNCTION NXTTS  (appr. line 430) is comment.

And even after fixing that, CodeTools (jump to implementation etc.) don't seem to work anymore.

Bart
« Last Edit: September 19, 2018, 08:34:30 pm by Bart »

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Compile a very old Pascal Source with FPC
« Reply #6 on: September 19, 2018, 08:36:50 pm »
The Highlighter used in Lazaus IDE does not like the source.
After applying the change sproposed by skalogryz, the highlighter thinks that everything after
Right click on the source. "File Settings" -> "Highlighter" -> "Delphi"
this should do the trick.
(also switching Project info -> Parsing -> Syntax Mode -> "Delphi" might also help).

For ultimate Lazarus happiness you might want to change "AS" constant to "AS_".

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: Compile a very old Pascal Source with FPC
« Reply #7 on: September 19, 2018, 08:39:24 pm »
Hmm oldies but good project so I compiled by upper advises and I start to talk to software :)

Code: Pascal  [Select][+][-]
  1. xx@xx:~/xx/projects$ ./chess05gnu
  2.  HI.  THIS IS CHESS .5
  3.  ENTER MOVE OR TYPE GO.
  4. LE FNODEL 1000
  5. BO
  6.  BO
  7. IN
  8.  IN
  9.  ENTER MOVE OR TYPE GO.
  10. MY MOVE - P-Q4.
  11.  MY MOVE - P-Q4.
  12.    ^
  13. * INVALID COMMAND
  14.          
  15.  

There are some related sites:

http://www.andreadrian.de/schach/
and
http://www.moorecad.com/standardpascal/ByteChess.txt

Added :
Some commands working:
Code: Pascal  [Select][+][-]
  1. ./chess05gnu
  2.  HI.  THIS IS CHESS .5
  3.  ENTER MOVE OR TYPE GO.
  4. pr
  5.  
  6. PR
  7.  PR
  8.  
  9.  8 rnbqkbnr
  10.  7 pppppppp
  11.  6 --------
  12.  5 --------
  13.  4 --------
  14.  3 --------
  15.  2 PPPPPPPP
  16.  1 RNBQKBNR
  17.                            
« Last Edit: September 19, 2018, 08:53:34 pm by tr_escape »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Compile a very old Pascal Source with FPC
« Reply #8 on: September 19, 2018, 08:42:05 pm »
Start program in Debugger, type GO (needed to do this twice for some reason):

Project chess05gnu raised exception class 'External: SIGFPE'.

In file 'chess05gnu.pas' at line 306:
SIGN := TRUNC(B/ABS(B)) * ABS(A);

If I can believe the debugger, then both A and B are zero at that point.

Bart
« Last Edit: September 19, 2018, 08:53:19 pm by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Compile a very old Pascal Source with FPC
« Reply #9 on: September 19, 2018, 08:59:09 pm »
Fixed SIGN
Code: Pascal  [Select][+][-]
  1. FUNCTION SIGN(A,B:TI): TI;             (* SIGN OF B APPLIED TO
  2.                                           ABSOLUTE VALUE OF A *)
  3.  
  4. BEGIN
  5.   if (B=0) then SIGN := 0
  6.   else
  7.   SIGN := TRUNC(B/ABS(B)) * ABS(A);
  8. END;  (* SIGN *)

Now at least I'm getting somewhere.

Code: [Select]
C:\Users\Bart\LazarusProjecten\bugs\forum\chess>chess05gnu
 HI.  THIS IS CHESS .5
 ENTER MOVE OR TYPE GO.
GO

GO
 GO
   MY MOVE - P-KK4.

Now to find the correct syntax for moves.
What the hell does P-KK4 mean?

Bart

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: Compile a very old Pascal Source with FPC
« Reply #10 on: September 19, 2018, 09:10:06 pm »
Fixed SIGN
Code: Pascal  [Select][+][-]
  1. FUNCTION SIGN(A,B:TI): TI;             (* SIGN OF B APPLIED TO
  2.                                           ABSOLUTE VALUE OF A *)
  3.  
  4. BEGIN
  5.   if (B=0) then SIGN := 0
  6.   else
  7.   SIGN := TRUNC(B/ABS(B)) * ABS(A);
  8. END;  (* SIGN *)

Now at least I'm getting somewhere.

Code: [Select]
C:\Users\Bart\LazarusProjecten\bugs\forum\chess>chess05gnu
 HI.  THIS IS CHESS .5
 ENTER MOVE OR TYPE GO.
GO

GO
 GO
   MY MOVE - P-KK4.

Now to find the correct syntax for moves.
What the hell does P-KK4 mean?

Bart


There are some related sites:

http://www.andreadrian.de/schach/
and
http://www.moorecad.com/standardpascal/ByteChess.txt

Try
PR
:)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: Compile a very old Pascal Source with FPC
« Reply #12 on: September 19, 2018, 09:39:42 pm »
Actually these days it is difficult to use as end user but it was a nice historical exercise :) 

The last edited and fixed (Bart's sign) version of chess05gnu is in the attach:

toaopeter

  • Newbie
  • Posts: 4
Re: Compile a very old Pascal Source with FPC
« Reply #13 on: September 19, 2018, 11:26:39 pm »
Guys, I am ... this is ... I am really very excited. Nighttime here in Germany. Need to go to bed.

Will check this tomorrow.

A BIG THANK YOU for all your efforts.

This is how to use this old baby:

For the user 's convenience , the program should be able to respond to a few simple commands . Inputs to the program are processed by a lengthy routine , READER, which has many component subprocedures. The translation of the input string is handled by a group of routines: R D RE R R, R D RG NT, RDRSFT, RDRCMP, RDLINE, RDRMOV and RDRNUM . Each of the commands is executed by a separate routine.
When the human player wishes to terminate the game before it has reached its conclusion (eg: when he is hopelessly lost and does not want to stay around to be crushed), he can simply type an END command and the ENDCMD routine will terminate the program . If the user simply wishes to start a new game, he can type INIT and the INICMD routine will set up for a new game.
   
If the user would like to set up a specific position from the previous game or some other game, he can call the BOACMD routine, which will set up any position he desires. To use this instruction, the pieces are designated in the standard way (eg: K, Q, R, B, N and P) and the colors are designated by L for light and D for dark. The board is described by starting at the lower lefthand corner and listing, row by row, the 64 squares. Numbers are used to represent consecutive empty squares. The command to set up the position after 1. P-K4, P-K4, 2. N-KB3, N-QB3 is: BOARD, LRNBQKB1 RPPPP1PPP5N24P34DP33N4PPPPIPPPR1B QKBNR.
If the human player is lazy or simply wishes to test the program, he or she can type GO and the machine will select a move. By repeatedly typing GO the user can sit back and watch the machine play against itself. The routine that handles this is GONCMD. To specify a value for selected program parameter variables, the player can use LETCMD. For example, the amount of time the machine spends calculating a move can be controlled by specifying a limit for the number of nodes to be searched. The command LET FNODEL = 1000 will cause the machine to set a target value of 1000 for the number of nodes to be searched. In this case it will not start another iteration if it has already searched 1000 nodes. If the user is confused about the current board configuration, the command PRINT will activate PRICMD which calls PRINTB for a representation (8 by 8 array) of the board. For diagnostic purposes the user can also ask for other information. The routine PAMCMD is activated by PB and provides an 8 by 8 attack map for each of the 64 squares. The routine POPCMD is activated by PO and gives information concerning the side to move (White or Black), the en passant status after the last move, the present castle status and the move number. If the user types PM, the routine PMVCMD will provide a list of all moves which are legal for the side to move in the current position. The command PL activates PLECMD which prints the value of a designated variable; for example, the user can determine the present limit for the number of nodes to be searched by typing PL FNODEL.
The user also has control over several switches. He can ask the machine to repeat (echo) each entry, to pause after 20 lines of output, and to reply automatically each time the opponent enters a move. These switches are set by the switch commands (eg: SW EC OFF), and are processed by SWICMD. If the user wishes to manually alter one or more of the status conditions

(eg: side to move, move number, en passant, castling), this can be done by activating STACMD.
Notes on Notation
The program also processes standard chess notation. This is not strictly necessary. Many programs use their own convention for entering and reporting moves. A common procedure is to denote the squares using a number (1 through 8) for each row and a letter (A through H) for each column. A move is defined by listing the present square of the piece and then the destination square. For example, the common opening move, P-K4, would be E2E4. Moving the White Knight on the kingside from its original square to KB3 would be G1 F3. This convention works nicely but it forces an experienced chess player to learn a new system. Most would prefer standard chess notation.
Because there are multiple ways to express the same move in standard notation, the translation routine needs to be fairly sophisticated. Consider a position in which the White Queen's Rook is on its original square and the neighboring Knight and Bishop have been moved. A move which places the Rook on the Queen Bishop file can be designated as R-B1, R-QB1, R/1-B1, R/1-QB1, R/R1-B1, or R/R1-QB1. It is important that the program recognize that each of these character strings represents the same move. How is this done?
One way is to have the machine generate a list of all legal moves and then compare each of these with the move entered by the player. If his move matches one on the list, that move is noted. The rest of the list is then checked and if no more matches are found, the noted move is assumed to be the correct one. If no match is found, the machine prints "illegal move." If a second match is found (eg: P-B3 matches both P-KB3 and P-QB3), the machine prints "ambiguous move." The process of translating the opponent's move into machine compatible form and checking its legality or ambiguity is done by YRMOVE. The process of translating the machine's move into standard notation is handled by MYMOVE. Both of these procedures call MINENG, which is responsible for constructing the appropriating character strings.



tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: Compile a very old Pascal Source with FPC
« Reply #14 on: September 20, 2018, 07:57:19 am »
The last news about this software is can be found in that repo maybe someone would like to edit for more graphical (!) usage...

https://github.com/mehmetulukaya/chess05gnu

 

TinyPortal © 2005-2018