Pascal Crosscompiler Advice

Anything QL Software or Programming Related.
Derek_Stewart
Font of All Knowledge
Posts: 3928
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Pascal Crosscompiler Advice

Post by Derek_Stewart »

Hi,

I have followed all the instructions in Norman CrossCompiler Buld document and verified with the FPC Sinclair QL WIKI page.

The Free Pacal compiler compiles a Pacal programme OK.

I have built the Crosscompiler seems to work as per the build doc.

When I type in:

Code: Select all

derek@lp1:~/SourceCode/Pascal$ fpc-ql -Tsinclairql hello.pp

Free Pascal Compiler version 3.3.1 [2021/04/16] for m68k
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Sinclair QL
Compiling hello.pp
Fatal: Can't find unit system used by hello
Fatal: Compilation aborted
Clearly the Crosscompiler is working, but can not find the Sinclair QL system unit, which should be located in:

~/bin/lib/fpc/3.3.1/units/m68k-sinclairql

as defined in the file: ~/bin/lib/fpc/etc/fpc.cfg

which I have defined as:

Code: Select all

#IFDEF CPUM68K
-Fu/home/derek/bin/lib/fpc/$fpcversion/units/$fpccpu-$fpcos
-Fu/home/derek/bin/lib/fpc/$fpcversion/units/$fpccpu-$fpcos/*
#IFDEF SINCLAIRQL
-FD/usr/local/bin
-XPm68k-sinclairql-
#ENDIF
#ENDIF
I have clearly missed something on the Crosscompiler configuration, I would be grateful of any help.


Regards,

Derek
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Pascal Crosscompiler Advice

Post by NormanDunbar »

Hi Derek,

Here's something that might help, from Chain-Q:
Chain-Q wrote:Another hint: Debugging config file and path issues is quite easy using the -vv compiler argument. This will write a file called "fpcdebug.txt" into the current directory, which contains human readable verbose information about the config file parsing, telling you what it expands those $foobar templates into, and if it can find the path or not. Among a lot of other internal information.
Compile again with -vv and see what config file it's looking for in the file named fpcdebug.txt. That might help. Post here if not.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Derek_Stewart
Font of All Knowledge
Posts: 3928
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Pascal Crosscompiler Advice

Post by Derek_Stewart »

Hi Norm,

Thank you for the update, I was reading all the Free Pacal documentation, but must of missed the compiler options.

The option to get the 'fpcdebug.txt' file in the current data directory is actually: -Vv

Which the resulting 'fpcdebug.txt' file helped i n showing that I had an old .fpc.cfg file in the home directory from a early version of Free Pascal that I compiled from source.

I renamed the .fpc.cfg to .fpc.cfg.old and the Crosscompiler compiled as stated in your Crosscompiler document.

I compiled the hello.pp file with:

fpc-ql -Tsinclairql -WQqhdr hello.pp

Which produced the output described and using Q-emulator, was abloe to execute the file 'hello.exe'

But the file 'hello.exe' would not execute in QPC2 or SMSQmulator, SMSQ/E still thinking it was a Type 0 or data file.


Regards,

Derek
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Pascal Crosscompiler Advice

Post by NormanDunbar »

Hi Derek,
Derek_Stewart wrote:I compiled the hello.pp file with:

fpc-ql -Tsinclairql -WQqhdr hello.pp

Which produced the output described and using Q-emulator, was abloe to execute the file 'hello.exe'

But the file 'hello.exe' would not execute in QPC2 or SMSQmulator, SMSQ/E still thinking it was a Type 0 or data file.

Back in Linux, I think you also use Mint? where the hello.exe file lives, do this:

Code: Select all

file hello.exe
You will get one of two responses:
  • QDOS executable 'FPC_PROG' - in which case the file compiled with an XTCC trailer and will need processing to convert it from a normal type 0 file to an executable file.
  • Data - in which case you should have an embedded header that QPC definitely understands and possibly Qemulator and others too.
I use QPC and when I compile with "-WQqhdr" I can execute them from my dos1_ drive, so I don't even have to copy them to a QL directory/device before executing. I'm running QPC 5.xx which is the latest from a couple of months ago.

This might give you a clue too. The header is in the first 32 or so bytes of the exe file. Try this:

Code: Select all

hexdump -C -n 48 hello.exe
You should see something like this:

Code: Select all

hexdump -C -n 48 sysvars.exe
00000000  5d 21 51 44 4f 53 20 46  69 6c 65 20 48 65 61 64  |]!QDOS File Head|
00000010  65 72 00 0f 00 01 00 00  33 c8 00 00 00 00 60 38  |er......3.....`8|
00000020  00 00 00 00 4a fb 00 08  46 50 43 5f 50 52 4f 47  |....J...FPC_PROG|
If you see this, then the file is definitely executable in QPC and was correctly compiled with the "-WQqhdr" option (which is also the default if no "-WQ" option is passed on the command line or in the config file.

The usual job header starts at address $20 in the above output. The executable header for emulators is in the first 32 bytes.

If you still have problems, can you zip up and post the hello.exe file that doesn't work for you and I'll check it out here. Thanks.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Derek_Stewart
Font of All Knowledge
Posts: 3928
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Pascal Crosscompiler Advice

Post by Derek_Stewart »

Hi Norm,

I am using Mint 19.3 Cinnamon, FPC v3.3.1

I checked the compiled hello.exe file which gave data from the Linux file command.

I noticed I was using QPC2 4.05, so I upgrade to 5.00 and the hello.exe file executes from QPC2 DOS drive.

If in Q-emulator, I copy the hello.exe to a QWA container, the QDOS file header is removed and other emulator and real hardware can execute the crosscompiled programme.

I thought I knew all about QDOS file headers, but this something I missed.


Regards,

Derek
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Pascal Crosscompiler Advice

Post by NormanDunbar »

Derek_Stewart wrote:I noticed I was using QPC2 4.05, so I upgrade to 5.00 and the hello.exe file executes from QPC2 DOS drive.
Excellent. I am 99% certaing that QPC 5 was when this style of header was able to be executed. I've been using XTcc trailers until recently, when Marcel gave me a telling off -- after all the work he did on QPC to implement them. :-)

Glad it's working now.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Derek_Stewart
Font of All Knowledge
Posts: 3928
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Pascal Crosscompiler Advice

Post by Derek_Stewart »

Hi Norm,

It seems that the crosscompiler was working before I posted this message thread. I actually had downloaded the source to Free Pascal and Lazarus and compiled it perfectly.

I like to compile software from source, rather than use install binary files.

I seem to of spent more time getting this rediculous QDOS header system working correctly.

Q-emulator (registered version) strips off the QDOS header file leaving a standard executable programme that can be run on real QL hardware.


Regards,

Derek
User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Pascal Crosscompiler Advice

Post by mk79 »

NormanDunbar wrote:Excellent. I am 99% certaing that QPC 5 was when this style of header was able to be executed. I've been using XTcc trailers until recently, when Marcel gave me a telling off -- after all the work he did on QPC to implement them. :-)
At last! Somebody who actually listens to me :-D


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Pascal Crosscompiler Advice

Post by mk79 »

Derek_Stewart wrote:Q-emulator (registered version) strips off the QDOS header file leaving a standard executable programme that can be run on real QL hardware.
QPC does the same. You do have to use a version that supports it, though (so v5 as you found out).


User avatar
Chain-Q
Chuggy Microdrive
Posts: 62
Joined: Mon Nov 16, 2020 1:10 pm
Location: Berlin, DE, EU
Contact:

Re: Pascal Crosscompiler Advice

Post by Chain-Q »

Derek_Stewart wrote: I compiled the hello.pp file with:

fpc-ql -Tsinclairql -WQqhdr hello.pp

Which produced the output described and using Q-emulator, was abloe to execute the file 'hello.exe'

But the file 'hello.exe' would not execute in QPC2 or SMSQmulator, SMSQ/E still thinking it was a Type 0 or data file.
Two things.

1., specifying -WQqhdr manually is not necessary, as it is the default.
2., there's -WQxtcc instead, which results in an XTcc style trailer (and the QHDR omitted), which means the cross compiled executable runs in QPC2 and SMSQmulator, and allows easy transfer to real hardware, without any further Q-emuLator magic or post processing (Fix me?).

If any of the above doesn't work how I described, that's a bug, please report and it will be fixed.


Post Reply