Recent

Author Topic: Porting TP3 code to Lazarus  (Read 2393 times)

domasz

  • Sr. Member
  • ****
  • Posts: 435
Porting TP3 code to Lazarus
« on: November 12, 2023, 03:59:35 pm »
I found a nice program which compiles with Turbo Pascal 3 and works fine. Version compiled with Turbo Pascal 7 does not work.

I want to port it to Lazarus. I tried {$mode tp} but it's not enough. I replaced all integers in source code with "integer2" and defined:
Code: Pascal  [Select][+][-]
  1. type integer2 = int16;  
But that's not enough. How can I force int16 on all operations, constants etc.? So for eg.
Code: Pascal  [Select][+][-]
  1. const
  2.     recognize  = $FF76;
is equal to -138.

There is also this in source code:
Code: Pascal  [Select][+][-]
  1. writeln('Input file ', in_fn,' is ',infilesize * 128,' bytes.');
For some reason FileSize in TP3 needs to be multiplied by 128 to give correct size.

Attached code and a sample file for the curious people.
« Last Edit: November 12, 2023, 04:17:17 pm by domasz »

cpicanco

  • Hero Member
  • *****
  • Posts: 618
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Porting TP3 code to Lazarus
« Reply #1 on: November 12, 2023, 04:18:24 pm »
Hi, sorry if this is not what you were looking for but I did a simple test here and typecasting

Int16($FF76)

works great
Be mindful and excellent with each other.
https://github.com/cpicanco/

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Porting TP3 code to Lazarus
« Reply #2 on: November 12, 2023, 04:41:14 pm »
Yes, typecasting that constant helps but the program doesn't work properly so somewhere else might be a similar problem. Or completely different, you never know.

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Porting TP3 code to Lazarus
« Reply #3 on: November 12, 2023, 04:47:50 pm »
OK, I made it work on the test file. I'll need more test files to confirm this is fixed now but here's what I did.

In TP3 manual:
Quote
The standard function EOF works as with typed files. So do standard
functions FilePos and FileSize and standard procedure Seek, using a
component size of 128 bytes (the record size used by BlockRead and
Block Write).

So I did:
Code: Pascal  [Select][+][-]
  1. infilesize := filesize(in_file); (* filesize at initiate *)
  2. infilesize := infilesize div 128;

Code: Pascal  [Select][+][-]
  1. blockwrite(out_file,outfilebuffer,1*128);
and
Code: Pascal  [Select][+][-]
  1. blockread(in_file, infilebuffer, infilesize*128);

cpicanco

  • Hero Member
  • *****
  • Posts: 618
  • Behavioral Scientist and Programmer
    • Portfolio
Re: Porting TP3 code to Lazarus
« Reply #4 on: November 12, 2023, 04:52:33 pm »
So, I am getting a range check error in line 244 regardless of answering Y or N. Does it help you somehow? You can enable debugging in lazarus going to Project -> Project Options-> Debugging -> check all "Checks and Assetions" checkboxes.

__

Just saw you got it
Be mindful and excellent with each other.
https://github.com/cpicanco/

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Porting TP3 code to Lazarus
« Reply #5 on: November 12, 2023, 05:03:06 pm »
The attached should work for you with no errors

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Porting TP3 code to Lazarus
« Reply #6 on: November 16, 2023, 11:28:30 am »
My small guide on porting Turbo Pascal 4 code to Lazarus 64 bit.

1) FileSize reports size correctly, in bytes. Unlike TP 3. Not sure why TP3 is so weird

2) All integers should be renamed to Int16

3) MaxInt constant should equal 32767

4) All variables of "file" type generally should be replaced with "file of byte".

5) All "records" to be replaced with "packed records". Some records require this to work, others don't but won't mind

« Last Edit: November 16, 2023, 11:42:11 am by domasz »

hansotten

  • Jr. Member
  • **
  • Posts: 89
Re: Porting TP3 code to Lazarus
« Reply #7 on: November 16, 2023, 01:25:57 pm »

1) FileSize reports size correctly, in bytes. Unlike TP 3. Not sure why TP3 is so weird


Turbo Pascal shows here its CP/M origin, files are multiples of 128 byte records.

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Porting TP3 code to Lazarus
« Reply #8 on: November 16, 2023, 01:29:17 pm »

1) FileSize reports size correctly, in bytes. Unlike TP 3. Not sure why TP3 is so weird


Turbo Pascal shows here its CP/M origin, files are multiples of 128 byte records.

That's interesting! Thanks! Are you aware of any other unusual things in old versions TP?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Porting TP3 code to Lazarus
« Reply #9 on: November 16, 2023, 01:30:45 pm »
Turbo Pascal shows here its CP/M origin, files are multiples of 128 byte records.

Possibly by way of dos, afaik the FCB size in old dos versions was 128 too, changing only with the introduction of handle based INTs (in 3 or 4, can't remember)

440bx

  • Hero Member
  • *****
  • Posts: 4031
Re: Porting TP3 code to Lazarus
« Reply #10 on: November 16, 2023, 05:50:50 pm »
This:

I want to port it to Lazarus.

and this:

My small guide on porting Turbo Pascal 4 code to Lazarus 64 bit.

I might be overly picky but, Lazarus is _not_ a programming language, therefore no Pascal code can be ported to Lazarus.  Turbo Pascal code can be ported to FPC but not Lazarus.

Pascal programmers rightfully express dissatisfaction with TIOBE's views towards the Pascal language, for that dissatisfaction to be justified then it's important to draw the lines where they really are. 

Off my soapbox now :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

domasz

  • Sr. Member
  • ****
  • Posts: 435
Re: Porting TP3 code to Lazarus
« Reply #11 on: November 16, 2023, 06:19:24 pm »

I might be overly picky but, Lazarus is _not_ a programming language, therefore no Pascal code can be ported to Lazarus.  Turbo Pascal code can be ported to FPC but not Lazarus.

You are right!

Pascal programmers rightfully express dissatisfaction with TIOBE's views towards the Pascal language, for that dissatisfaction to be justified then it's important to draw the lines where they really are. 

Well, TIOBE is retarded to say politely. They measure something but not what they claim they do.

 

TinyPortal © 2005-2018