Skip to content

Using the SDK

The clang-dos toolchain package has the sysroot in m68k-amigaos/, next to bin/, with the C library, the AmigaOS headers and libamiga.a. Then:

clang --target=m68k-amigaos -O2 hello.c -o hello
clang --target=m68k-amigaos -mcpu=68020 -O2 window.c -o window

The driver links crt0.o, libc.a, libamiga.a and the builtins with ld.lld --emit-relocs, and converts the result to a Hunk executable with llvm-elf2hunk. Code is for the 68000 unless -mcpu= says otherwise; the libraries are 68000 code, which runs on every CPU.

C programs

  • main(argc, argv) gets the CLI arguments, split as the CLI does. Started from Workbench, argc is 0 and argv is the struct WBStartup message; stdin/stdout/stderr then open a console window when first used.
  • malloc takes memory from AllocMem(); what is left is freed at exit.
  • printf, files (fopen, open, stat, rename, mkdir, ...) and time (time, clock_gettime, nanosleep) work as in POSIX, with AmigaOS paths (DH0:dir/file, RAM:).
  • The CLI's default stack (4000 bytes on Kickstart 1.3) is small for printf: run Stack 20000 first.

OS calls

Include <proto/exec.h>, <proto/dos.h>, <proto/intuition.h> and so on, as with other Amiga compilers. The calls go through libamiga.a, whose stubs move the arguments into the library's registers and call it through its base. SysBase and DOSBase are set up by the C library; open other libraries yourself and set their base variable (IntuitionBase, GfxBase, ...), as in examples/window.c.

proto/*.h declare the library base and include clib/*_protos.h; there is no inline assembly. clang has no register parameters, so function pointer types with register arguments (hooks, for example) are ordinary C ones.

libamiga.a also has the helper functions of the classic link libraries, written for this SDK (os/alib):

  • amiga.lib (<clib/alib_protos.h>):
  • hooks and BOOPSI: HookEntry, CallHookA/CallHook, DoMethodA/DoMethod, DoSuperMethodA/DoSuperMethod, CoerceMethodA/CoerceMethod, SetSuperAttrs. For a hook written in C, put HookEntry in h_Entry and the C function in h_SubEntry; it is called as func(hook, object, message);
  • exec: NewList, CreatePort/DeletePort, CreateExtIO/DeleteExtIO, CreateStdIO/DeleteStdIO, CreateTask/DeleteTask, BeginIO, LibCreatePool and friends (exec's pools from V39, a simple version before);
  • TimeDelay, DoTimer, FastRand, RangeRand, ACrypt, AddTOF/RemTOF (a C function called at every vertical blank) and waitbeam (open graphics.library as GfxBase);
  • tool types (ArgArrayInit, ArgArrayDone, ArgString, ArgInt; open icon.library as IconBase) and commodities (HotKey, InvertString, FreeIEvents; open commodities.library as CxBase);
  • debug.lib (<clib/debug_protos.h>): KPrintF, KPutStr, KPutChar, KGetChar, KGetNum, ... on the serial port, through exec's raw I/O, so they work anywhere, even with interrupts off;
  • ddebug.lib (<clib/ddebug_protos.h>): the same as DPrintF and so on, on the parallel port;
  • reaction.lib (<clib/reaction_lib_protos.h>): ClickTabs, ChooserLabels, RadioButtons, BrowserNodes and their Free*, LBAddNode/LBEditNode/LBRemNode, GetAttrs, GetCode, LibDoGadgetMethod and OpenLayoutWindowTags. Open the class library each one uses (ClickTabBase, ..., LayoutBase).

ACrypt, FastRand and RangeRand compute what AmigaOS's do, as in AROS (AROS Public License); the rest is written for this SDK. examples/alibtest.c checks them. Not there yet: the ARexx variable functions (CheckRexxMsg, GetRexxVar, SetRexxVar) and the FFP conversions (see os/README.md).