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,argcis 0 andargvis thestruct WBStartupmessage;stdin/stdout/stderrthen open a console window when first used.malloctakes memory fromAllocMem(); 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: runStack 20000first.
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.
Link library functions¶
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, putHookEntryinh_Entryand the C function inh_SubEntry; it is called asfunc(hook, object, message); - exec:
NewList,CreatePort/DeletePort,CreateExtIO/DeleteExtIO,CreateStdIO/DeleteStdIO,CreateTask/DeleteTask,BeginIO,LibCreatePooland 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) andwaitbeam(open graphics.library asGfxBase);- tool types (
ArgArrayInit,ArgArrayDone,ArgString,ArgInt; open icon.library asIconBase) and commodities (HotKey,InvertString,FreeIEvents; open commodities.library asCxBase); - 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 asDPrintFand so on, on the parallel port; - reaction.lib (
<clib/reaction_lib_protos.h>):ClickTabs,ChooserLabels,RadioButtons,BrowserNodesand theirFree*,LBAddNode/LBEditNode/LBRemNode,GetAttrs,GetCode,LibDoGadgetMethodandOpenLayoutWindowTags. 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).