Difference between revisions of "Atari"

From Lazarus wiki
Jump to navigationJump to search
m (documented AppType)
(→‎Assembler: vasm did an oopsie, but it has been fixed)
 
(15 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
==Status==
 
==Status==
  
The initial port was done by [[User:Chain-Q|Károly Balogh]], maintainer of the [[m68k]] and [[Amiga]] ports, based on some existing bits from FPC 0.x and 1.x times done by Carl Eric Codere and others. The Atari TOS port lacks a maintainer currently. This means although we try to keep it working and do minor fixes to it, the port receives no new features. '''Contact the [[m68k]] port maintainer, if you are interested in stepping up as an Atari maintainer.'''
+
The initial port was done by [[User:Chain-Q|Károly Balogh]], maintainer of the [[m68k]] and [[Amiga]] ports, based on some existing bits from FPC 0.x and 1.x times done by Carl Eric Codere and others. The port was further improved thanks to the extensive contributions by Thorsten Otto. The Atari TOS port lacks a maintainer currently. This means although we try to keep it working and do minor fixes to it, the port receives no new features. '''Contact the [[m68k]] port maintainer, if you are interested in stepping up as an Atari maintainer.'''
  
The RTL support is reasonably advanced, and it's sufficient to run the compiler itself on Atari TOS, but - given the real hardware's constraints - it's not extensively tested. The largest known basic chunk missing from the RTL is the DOS unit, although it's now considered legacy, it's still required for some packages, and lots of legacy code. A "tosunits" package is also missing (or very minimal), which means FPC provides no bindings for most of the OS AP useable by applications at this point.
+
'''The Atari port is in a low support tier, which means we don't really support "stable" compiler versions.''' This document reflects the status in the "main" branch.
 +
 
 +
The RTL support is reasonably advanced, and it's sufficient to run the compiler itself on Atari TOS, but - given the real hardware's constraints - it's not extensively tested. Most of the System, Sysutils and DOS units are implemented, some parts of it are not, or not very well tested though. The "tosunits" package is available for direct OS call bindings, and are fairly complete at this point. See section [[#OS Bindings|OS Bindings]] for details. The Atari TOS port doesn't support MiNT long file names at this point.
  
 
==Identification==
 
==Identification==
Line 22: Line 24:
 
==SysCalls==
 
==SysCalls==
  
Free Pascal supports generating Atari TOS-style system calls, also know as traps. It's not required to use inline assembly to do system calls. However, you must declare every function you're going to use in the following way:
+
Free Pascal supports generating Atari TOS-style system calls, also known as traps. It's not required to use inline assembly to do system calls. However, you must declare every function you're going to use in the following way:
 
   
 
   
 
<syntaxhighlight lang="pascal">function gemdos_fwrite(handle: smallint; count: longint; buf: pointer): longint; syscall 1 64;
 
<syntaxhighlight lang="pascal">function gemdos_fwrite(handle: smallint; count: longint; buf: pointer): longint; syscall 1 64;
Line 29: Line 31:
  
 
==Linker==
 
==Linker==
For Atari, some versions of GNU ld linker available online is known to be problematic when working together with Free Pascal. It's recommended to use '''vlink''' by Frank Wille, while compiling to Atari TOS with FPC. Specifying ''-XV'' argument enables '''vlink''' for cross compilers. The native compiler defaults to '''vlink''', to switch the linker back to '''GNU ld''' use ''-XV-'' argument.
+
For Atari, some versions of '''GNU ld''' linker available online is known to be problematic when working together with Free Pascal. It's recommended to use '''vlink''' by Frank Wille, while compiling to Atari TOS with FPC. Specifying ''-XV'' argument enables '''vlink''' for cross compilers. The native compiler defaults to '''vlink''', to switch the linker back to '''GNU ld''' use ''-XV-'' argument.
 +
 
 +
'''vlink''' is open source, and it is available [http://sun.hasenbraten.de/vlink here]. Binaries are available as part of the [http://sun.hasenbraten.de/vbcc vbcc compiler package]. For advanced features like named sections and section garbage collection, use vlink 0.15d or newer.
 +
 
 +
Due to TOS executable format limitations, code compiled for 68020 and newer CPUs might not work at this time, so use the option ''-Cp68000'' to force the compiler to 68000 only mode. See the additional notes about 68000 constraints on the [[m68k]] page.
 +
 
 +
==Assembler==
 +
The Atari TOS port supports both '''GNU as''' assembler and '''vasm'''. Advanced features like named sections support are only available with '''vasm'''. To compile with vasm, you need to specify the argument ''-Avasm'' compile time. Please note that mixing '''GNU as''' and '''vasm''' compiled objects might cause issues during linking.
 +
 
 +
'''vasm''' is open source, and it is available [http://sun.hasenbraten.de/vasm here]. Binaries are available as part of the [http://sun.hasenbraten.de/vbcc vbcc compiler package]. Only vasm versions 1.7h and newer were tested, older versions might not work.
 +
 
 +
<span style="color:red">'''WARNING:''' '''vasm''' versions between 1.9a and 1.9c - these versions inclusive - contain a bug, which makes it impossible to use these versions with Free Pascal on any [[m68k]] platform. '''Please stick to vasm versions 1.8 (any letter), 1.9 (no letter) or 1.9d, or newer.'''</span>
 +
 
 +
====Building vasm for FPC====
 +
 
 +
Note that '''vasm''' for m68k needs to be built with the ''standard'' syntax module to work with FPC. This is not the default, as most coders and compilers (like vbcc itself) 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:
 +
 
 +
<syntaxhighlight lang="bash">
 +
make CPU=m68k SYNTAX=std
 +
</syntaxhighlight>
  
'''vlink''' is open source, and it is available [http://sun.hasenbraten.de/vlink here]. Binaries are available as part of the [http://sun.hasenbraten.de/vbcc vbcc compiler package].
+
The resulting ''vasmm68k_std'' executable file is the assembler is the one FPC needs.
  
 
==Cross compiling==
 
==Cross compiling==
  
 +
===Dependencies===
 +
Free Pascal requires cross-binutils for the target platform. Additionally, the TOS version also needs '''vlink''' and optionally '''vasm'''. For Atari TOS/MiNT cross-binutils for various platforms, also as binary downloads, [http://vincent.riviere.free.fr/soft/m68k-atari-mint/ see this page by Vincent Rivière]. For [[#Linker|vlink]] and [[#Assembler|vasm]] see the relevant sections above.
 +
 +
===Building===
 
To build an Atari cross-compiler, use the following steps:
 
To build an Atari cross-compiler, use the following steps:
  
# Install the latest stable FPC version, at the time of the writing of this article this is FPC 3.0.0. This will be used as the startup compiler.
+
# Install the latest stable FPC version, at the time of the writing of this article this is FPC 3.2.2. This will be used as the startup compiler.
# Check out FPC SVN trunk into a directory.
+
# Clone the FPC git repository.
# Make sure you have Atari TOS cross-binutils and vlink in the PATH.
+
# Make sure you have Atari TOS cross-binutils and vlink, and optionally vasm in the PATH.
# Go to the trunk's main directory and use the following command to build an FPC cross-compiler:
+
# Go to the repository's directory, make sure you are on the '''main''' branch and use the following command to build an FPC cross-compiler:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
   make clean crossall crossinstall OS_TARGET=atari CPU_TARGET=m68k INSTALL_PREFIX="<path/to/install>"
+
   make clean crossall crossinstall OS_TARGET=atari CPU_TARGET=m68k CROSSOPT="-Cp68000" INSTALL_PREFIX="<path/to/install>"
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Or, to build everything with vasm instead, use:
 +
 +
<syntaxhighlight lang="bash">
 +
  make clean crossall crossinstall OS_TARGET=atari CPU_TARGET=m68k CROSSOPT="-Avasm -Cp68000" INSTALL_PREFIX="<path/to/install>"
 +
</syntaxhighlight>
 +
 
If you've done everything right, you should find a working Atari cross-compiler in the install path you've specified.
 
If you've done everything right, you should find a working Atari cross-compiler in the install path you've specified.
  
Line 53: Line 85:
 
  #IFDEF ATARI
 
  #IFDEF ATARI
 
  -FD</path/to/atari-cross-binutils>
 
  -FD</path/to/atari-cross-binutils>
 +
-Cp68000
 
  -XV
 
  -XV
 
  #ENDIF
 
  #ENDIF
 
  #ENDIF
 
  #ENDIF
  
Optionally add '''<path/to/install>/lib/fpc/3.1.1/''' directory to the PATH, so you'll have direct access to the cross-compiler. If you've done everything right, you now should be able to build Atari executables:
+
Optionally add '''<path/to/install>/lib/fpc/3.3.1/''' directory to the PATH, so you'll have direct access to the cross-compiler. If you've done everything right, you now should be able to build Atari executables:
  
 
  ppcross68k -Tatari <source.pas>
 
  ppcross68k -Tatari <source.pas>
 +
 +
==OS Bindings==
 +
 +
The "tosunits" package contains the direct OS bindings, and it's fairly complete at this point. It provides '''AES''', '''VDI''', '''GEMDOS''' and '''XBIOS''' bindings. The bindings were developed using the [http://toshyp.atari.org/en/index.html tos.hyp documentation], and various other bits of information available around the net. The still missing bindings should be very easy to add, using the existing ones as a template. Some work has been included to be compatible with Pure Pascal OS bindings, therefore support compiling of existing code.
 +
 +
===Naming differences===
 +
 +
The bindings try to follow the established function names for OS functions. However, there are some differences compared to the C language, to avoid confusion caused by collisions in the global namespace. The most important are:
 +
 +
* All '''GEMDOS''' functions start with the prefix ''gemdos_''. For example ''fwrite()'' becomes ''gemdos_fwrite()''.
 +
* All '''XBIOS''' functions start with the prefix ''xbios_''. For example ''random()'' becomes ''xbios_random()''.
 +
* As a de-facto convention with Pascal, all type names are prefixed with ''T'' and all pointers to those types are prefixed with ''P''. For example the '''AES''' ''MFORM'' structure is named ''TMFORM'' in Free Pascal, and a pointer to ''TMFORM'' is defined as ''PMFORM''. Additionally, the '''AES''' ''OBJECT'' structure is named ''TAESOBJECT'' to avoid conflict with the ''TObject'' class type defined in the ''System'' unit.
 +
 +
Note that most of these naming differences are not mandated, but simply there for practical reasons: to avoid confusion and cryptic error messages during compilation, in case a wrong type or function gets referenced with an overlapping name. If necessary to compile some older code, aliases with the regular naming can be added easily.
 +
 +
===Examples===
 +
 +
The "tosunits" package provides a few examples which show the bindings and '''TOS/GEM''' API used natively. Further contributions are welcomed.
 +
 +
==Missing features==
 +
 +
===Truncate===
 +
It's not possible to trivially implement a ''truncate()'' procedure on the original Atari TOS. This function is not supported by FPC on TOS. It might be implemented for a future MiNT support though.
  
 
[[Category: Operating Systems and Platforms]]
 
[[Category: Operating Systems and Platforms]]

Latest revision as of 10:15, 23 April 2023

This page is about the Atari TOS version of Free Pascal, which means Motorola 680x0 CPU based Atari systems running TOS and compatibles.

Status

The initial port was done by Károly Balogh, maintainer of the m68k and Amiga ports, based on some existing bits from FPC 0.x and 1.x times done by Carl Eric Codere and others. The port was further improved thanks to the extensive contributions by Thorsten Otto. The Atari TOS port lacks a maintainer currently. This means although we try to keep it working and do minor fixes to it, the port receives no new features. Contact the m68k port maintainer, if you are interested in stepping up as an Atari maintainer.

The Atari port is in a low support tier, which means we don't really support "stable" compiler versions. This document reflects the status in the "main" branch.

The RTL support is reasonably advanced, and it's sufficient to run the compiler itself on Atari TOS, but - given the real hardware's constraints - it's not extensively tested. Most of the System, Sysutils and DOS units are implemented, some parts of it are not, or not very well tested though. The "tosunits" package is available for direct OS call bindings, and are fairly complete at this point. See section OS Bindings for details. The Atari TOS port doesn't support MiNT long file names at this point.

Identification

To identify Atari TOS during compile-time, use {$IFDEF ATARI}.

AppType directive

Atari is among the few platforms actually support the $APPTYPE directive, originating from Delphi and Windows. There are currently two states:

  • $APPTYPE CONSOLE - the resulting executable will have .TTP extension
  • $APPTYPE GUI - the resulting executable will have .PRG extension

The default is CONSOLE, so compiled programs will have .TTP extension. The directive doesn't affect any other code generation or run-time behavior, except the resulting executable name.

SysCalls

Free Pascal supports generating Atari TOS-style system calls, also known as traps. It's not required to use inline assembly to do system calls. However, you must declare every function you're going to use in the following way:

function gemdos_fwrite(handle: smallint; count: longint; buf: pointer): longint; syscall 1 64;

Note the syscall modifier in the function declaration. The first argument to the syscall modifier is the trap number to call, and the second one is the trap opcode. All syscall parameters are passed on the stack and they're word (2 byte) aligned. For further examples, see rtl/atari/gemdos.inc in the RTL source.

Linker

For Atari, some versions of GNU ld linker available online is known to be problematic when working together with Free Pascal. It's recommended to use vlink by Frank Wille, while compiling to Atari TOS with FPC. Specifying -XV argument enables vlink for cross compilers. The native compiler defaults to vlink, to switch the linker back to GNU ld use -XV- argument.

vlink is open source, and it is available here. Binaries are available as part of the vbcc compiler package. For advanced features like named sections and section garbage collection, use vlink 0.15d or newer.

Due to TOS executable format limitations, code compiled for 68020 and newer CPUs might not work at this time, so use the option -Cp68000 to force the compiler to 68000 only mode. See the additional notes about 68000 constraints on the m68k page.

Assembler

The Atari TOS port supports both GNU as assembler and vasm. Advanced features like named sections support are only available with vasm. To compile with vasm, you need to specify the argument -Avasm compile time. Please note that mixing GNU as and vasm compiled objects might cause issues during linking.

vasm is open source, and it is available here. Binaries are available as part of the vbcc compiler package. Only vasm versions 1.7h and newer were tested, older versions might not work.

WARNING: vasm versions between 1.9a and 1.9c - these versions inclusive - contain a bug, which makes it impossible to use these versions with Free Pascal on any m68k platform. Please stick to vasm versions 1.8 (any letter), 1.9 (no letter) or 1.9d, or newer.

Building vasm for FPC

Note that vasm for m68k needs to be built with the standard syntax module to work with FPC. This is not the default, as most coders and compilers (like vbcc itself) 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 is the one FPC needs.

Cross compiling

Dependencies

Free Pascal requires cross-binutils for the target platform. Additionally, the TOS version also needs vlink and optionally vasm. For Atari TOS/MiNT cross-binutils for various platforms, also as binary downloads, see this page by Vincent Rivière. For vlink and vasm see the relevant sections above.

Building

To build an Atari cross-compiler, use the following steps:

  1. Install the latest stable FPC version, at the time of the writing of this article this is FPC 3.2.2. This will be used as the startup compiler.
  2. Clone the FPC git repository.
  3. Make sure you have Atari TOS cross-binutils and vlink, and optionally vasm in the PATH.
  4. Go to the repository's directory, make sure you are on the main branch and use the following command to build an FPC cross-compiler:
  make clean crossall crossinstall OS_TARGET=atari CPU_TARGET=m68k CROSSOPT="-Cp68000" INSTALL_PREFIX="<path/to/install>"

Or, to build everything with vasm instead, use:

  make clean crossall crossinstall OS_TARGET=atari CPU_TARGET=m68k CROSSOPT="-Avasm -Cp68000" INSTALL_PREFIX="<path/to/install>"

If you've done everything right, you should find a working Atari cross-compiler in the install path you've specified.

Now, lets create a default fpc.cfg for Atari cross compiling. Create a file called <path/to/install>/lib/fpc/etc/fpc.cfg. 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 ATARI
-FD</path/to/atari-cross-binutils>
-Cp68000
-XV
#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. If you've done everything right, you now should be able to build Atari executables:

ppcross68k -Tatari <source.pas>

OS Bindings

The "tosunits" package contains the direct OS bindings, and it's fairly complete at this point. It provides AES, VDI, GEMDOS and XBIOS bindings. The bindings were developed using the tos.hyp documentation, and various other bits of information available around the net. The still missing bindings should be very easy to add, using the existing ones as a template. Some work has been included to be compatible with Pure Pascal OS bindings, therefore support compiling of existing code.

Naming differences

The bindings try to follow the established function names for OS functions. However, there are some differences compared to the C language, to avoid confusion caused by collisions in the global namespace. The most important are:

  • All GEMDOS functions start with the prefix gemdos_. For example fwrite() becomes gemdos_fwrite().
  • All XBIOS functions start with the prefix xbios_. For example random() becomes xbios_random().
  • As a de-facto convention with Pascal, all type names are prefixed with T and all pointers to those types are prefixed with P. For example the AES MFORM structure is named TMFORM in Free Pascal, and a pointer to TMFORM is defined as PMFORM. Additionally, the AES OBJECT structure is named TAESOBJECT to avoid conflict with the TObject class type defined in the System unit.

Note that most of these naming differences are not mandated, but simply there for practical reasons: to avoid confusion and cryptic error messages during compilation, in case a wrong type or function gets referenced with an overlapping name. If necessary to compile some older code, aliases with the regular naming can be added easily.

Examples

The "tosunits" package provides a few examples which show the bindings and TOS/GEM API used natively. Further contributions are welcomed.

Missing features

Truncate

It's not possible to trivially implement a truncate() procedure on the original Atari TOS. This function is not supported by FPC on TOS. It might be implemented for a future MiNT support though.