Coding for AmigaOS.

AmigaOS is your bridge to the hardware.

An operating system serves as a bridge between the user and the computer’s hardware, while also providing routines and services that help applications run smoothly on the platform and take advantage of all the ready-made functionality the OS offers.

AmigaOS is no different, providing a rich set of routines you can tap into for your code. This made it far ahead of its time, and it’s still seen as both efficient and welcoming to coders and users alike.

Most routines are organized into libraries. For example, the intuition.library contains routines for managing windows and screens. If you need to open a file or read a directory in your code, the dos.library is the place to look. The graphics.library can help you draw a circle on the screen or animate an image by moving it around.

For a full guide to the built-in libraries, take a look at the official autodocs here:

https://developer.amigaos3.net/autodocs

Let’s dive in and explore how to work with all this functionality using assembler. To use a library’s contents, you first need to open it, and when you’re finished, close it properly. The one exception is the exec.library, which is always open and ready to use. This is the library that lets us open any other library.

movea.l 4.w,a6 ; At memory address 4 you will always find a pointer to ExecBase/SysBase

With ExecBase loaded in a6, we can call any of Exec’s functions. A library base is essentially a table of available functions, with the base pointing to the last one. To call a function, we use a negative offset from the base. Confusing, I know. An example is in order.

; Find ExecBase and use Exec's OpenLibrary funtion to open Intuition.
; Store IntuitionBase in a variable for later using it's functions.

_LVOOpenLibrary = -552
_LVOCloseLibrary = -414

Start:
		movea.l	4.w,a6			; ExecBase in a6
		lea	IntuitionName,a1	; Name of Intuition Library
		moveq	#0,d0			; Any version of the library is OK
		jsr	_LVOOpenLibrary(a6)	; Jump to Execbase - 552.
		move.l	d0,IntuitionBase	; Store IntuitionBase in memory

		; ... Lots of useful code ...

		movea.l	4.w,a6
		movea.l	IntuitionBase,a1	; Library to close
		jsr	_LVOCloseLibrary(a6)	; Always clean up and close after us.

		rts

IntuitionBase:	dc.l	0
IntuitionName:	dc.b	"intuition.library",0
		even

jsr _LVOOpenLibrary(a6) translates to jsr -552(a6), which means the CPU jumps to the address located 552 bytes before the address that a6 points to.

In the developer tools, you’ll come across include files—definitions you can add to your code that let you use function names instead of numbers. We’ll explore this in more detail in a later article. In the upcoming articles, you’ll also see more examples of how to use OS functions. It might feel a bit confusing at first, but it will start to click as you get more examples of how they’re used.