Skip to content

Using the SDK

The clang-dos toolchain package has the sysroot in m68k-atari-tos/, next to bin/. Then:

clang --target=m68k-atari-tos -O2 hello.c -o hello.tos
clang --target=m68k-atari-tos -O2 gemhello.c -o gemhello.prg
clang --target=m68k-atari-tos -mcpu=68030 -O2 game.c -o game.prg

The driver links crt0.o, libc.a, libgem.a and the builtins with ld.lld --emit-relocs and the sysroot's tos.ld, and converts the result to a TOS program with llvm-elf2tos. The output is a TOS executable whatever its name; the extension tells the desktop how to start it: .PRG for GEM programs, .TOS for text programs, .TTP for text programs that ask for arguments. Code is for the 68000 unless -mcpu= says otherwise; the libraries are 68000 code, which runs on every CPU.

The ABI is that of gcc for the Atari (m68k-atari-mint): int is 32 bits, everything of 2 bytes or more is aligned to 2, values and pointers are returned in d0, the struct-return pointer is passed in a1, and a6 is the frame pointer. long double is the same as double for now. There is no FPU code generation yet: floating point is done in software, which works on every machine.

C programs

  • main(argc, argv, envp) gets the command line, split at spaces with " and ' quoting, or the full arguments when the caller uses the ARGV environment convention. argv[0] is empty unless ARGV gives it. environ is the GEMDOS environment.
  • The program keeps its text, data, bss and a 32K stack, and gives the rest of memory back to GEMDOS. Define long _stksize = 65536; for another stack size (0 or less keeps all of memory, with the stack at its top).
  • malloc works from one block, taken from GEMDOS the first time it needs memory: all of the largest free block but 64K, or long _heapsize = ...; bytes. A program that starts other programs should set _heapsize, to leave them room.
  • printf, files (fopen, open, stat, rename, mkdir, chdir, getcwd, ...) and time (time, clock_gettime, clock, nanosleep) work as in POSIX. Paths are GEMDOS paths (C:\DIR\FILE.TXT); / is taken as \. Files are binary: there is no CR LF translation, except that writing \n to the console writes \r\n.
  • stdout is GEMDOS handle 1 and stdin handle 0; stderr is the console (handle -1), since GEMDOS handle 2 is the serial port.
  • Time is GEMDOS local time, taken as UTC, to 2 seconds, with the 200 Hz timer for the fraction. clock() and CLOCK_MONOTONIC use the 200 Hz timer.

OS calls

#include <osbind.h> and call Cconws("Hello\r\n"), Fopen(), Physbase(), Supexec() and so on, as with other Atari C compilers. The calls are macros that push the arguments in the sizes TOS expects and call trap #1 (GEMDOS), #13 (BIOS) or #14 (XBIOS). <mint/osbind.h> is the same header. Low memory (system variables, the cookie jar) can only be read in supervisor mode: use Supexec(), as examples/sysinfo.c does.

GEM

#include <gem.h> (or <aes.h> and <vdi.h>) for windows, menus, dialogs, alerts and VDI graphics; see examples/gemhello.c. The functions are in libgem.a, which the driver links when it is in the sysroot.