Sinclair QL

From Free Pascal wiki
Revision as of 16:08, 21 November 2020 by Chain-Q (talk | contribs) (→‎Stack: mention ways to change stack size)
Jump to navigationJump to search

The Sinclair QL or QDOS port is an experimental "just for fun" m68k target. It targets the Sinclair QL line of computers from the mid-80s, and their operating system QDOS. This port is currently a cross-compiler only target. This is mostly due to hardware limitations of the original unexpanded platform. Later QL clones could run the compiler in theory, however, there are no plans to support these due to their extreme rarity.

The QL port was implemented by Karoly Balogh during #QLvember 2020, when various online retro communities and YouTubers were running Sinclair QL related projects.

Requirements

The compiled binaries - depending on the size - should be able to run on any Sinclair QL. Memory expansion for more complex programs is highly recommended.

Identification

To identify the Sinclair QL compile-time, use {$IFDEF SINCLAIRQL}.

Stack

The default stack size is set to 8 KiB, which is quite small for a Pascal program. For more complex programs you'll probably need to increase it. To change the stack size, use the {SMEMORY <stacksize>,<heapsize>} directive, or the -Cs command line argument. See the details in the documentation.

CPU

The default CPU target for the Sinclair QL is the 68000. This is different from most other m68k targets where the default is the 68020. The SoftFPU is enabled by default for the QL.

Alignment

Record elements are aligned to WORD (2 bytes) on the Sinclair QL by default. Use the {$PACKRECORDS n} compiler directive, if you want to change the default aligment. For byte aligned records, a packed record is also possible. Free Pascal also has support for 68000/68008 special alignment requirements.

Assembler

The only supported assembler for the Sinclair QL port is vasm, which is also the default. The Sinclair QL uses the vasm-specific .vobj object format. This means using vasm also requires vlink as linker. vasm is open source, and it is available here. Only vasm versions 1.8 and newer were tested with the Sinclair QL port, older versions might not work.

Building vasm

Note that vasm for m68k needs to be built with the standard syntax module to work with Free Pascal. This is not the default, as most programmers and compilers prefer the Motorola syntax module. A vasm version with the standard syntax module can be built with the following command, issued in the root of the vasm source tree:

 make CPU=m68k SYNTAX=std

The resulting vasmm68k_std executable file is the assembler Free Pascal needs.

Linker

The Sinclair QL ports defaults to vlink by Frank Wille as the default linker, which is the only supported linker as well for this target. vlink is open source, and it is available here.

Please make sure you use vlink version 0.16c or newer. Earlier versions were not tested with Free Pascal and the Sinclair QL target.

Building

To build a Sinclair QL cross-compiler, follow these steps:

  1. Install the latest stable FPC version for your host platform. This will be used as the startup compiler.
  2. Check out FPC SVN trunk into a directory.
  3. Make sure you have the binaries vasmm68k_std and vlink in the PATH. (See above.) Their binaries must be named (or symlinked) as m68k-sinclairql-vasmm68k_std and m68k-sinclairql-vlink.
  4. Go to the trunk's main directory and execute the following commands:
  make clean OS_TARGET=sinclairql CPU_TARGET=m68k
  make crossall OS_TARGET=sinclairql CPU_TARGET=m68k
  make crossinstall OS_TARGET=sinclairql CPU_TARGET=m68k INSTALL_PREFIX="<path/to/install>"

If you did everything right, you will find a working Sinclair QL cross-compiler with the pre-built RTL and Packages units in the install path you've specified. If you plan to rebuild FPC often, you might want to put the above commands in a script for easy rebuilding.

Now, lets create a default fpc.cfg for Sinclair QL cross compiling. Create a file called <path/to/install>/lib/fpc/etc/fpc.cfg. (Note: this is the path on Unix systems. Free Pascal on other platforms might expect a different path.) Put the following lines into that file, and fix up the paths:

 #IFDEF CPUM68K
 -Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET
 -Fu<path/to/install>/lib/fpc/$fpcversion/units/$FPCTARGET/*
 #IFDEF SINCLAIRQL
 -FD</path/to/vasm-and-vlink>
 -XPm68k-sinclairql-
 #ENDIF
 #ENDIF

Optionally add <path/to/install>/lib/fpc/3.3.1/ directory to the PATH, so you'll have direct access to the cross-compiler. (Note: this is the path on Unix systems. Free Pascal on other platforms the ppcross68k compiler binary might be in a different path.) If everything went right, you now should be able to build Sinclair QL executables with:

 ppcross68k -Tsinclairql <source.pas>