Here's a simple "Hello World" program for the Commodore Amiga in C:
#include <exec/types.h>
#include <intuition/intuition.h>
#include <graphics/gfxmacros.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
int main()
{
struct Window *window;
struct IntuiMessage *message;
ULONG class;
BOOL done = FALSE;
/* Open Intuition library */
IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 0);
if (!IntuitionBase) return 1;
/* Open Graphics library */
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
if (!GfxBase) {
CloseLibrary((struct Library *)IntuitionBase);
return 1;
}
/* Open a window */
window = OpenWindow(&(struct NewWindow){
100, 50, /* left, top */
400, 200, /* width, height */
0, 1, /* detail pen, block pen */
CLOSEWINDOW, /* IDCMP flags */
WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | ACTIVATE,
NULL, /* first gadget */
NULL, /* checkmark */
"Hello Amiga!", /* window title */
NULL, /* screen */
NULL, /* bitmap */
0, 0, 0, 0, /* min/max width/height */
WBENCHSCREEN /* screen type */
});
if (!window) {
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)IntuitionBase);
return 1;
}
/* Draw text in the window */
SetAPen(window->RPort, 1);
Move(window->RPort, 50, 50);
Text(window->RPort, "Hello, Amiga World!", 19);
Move(window->RPort, 50, 70);
Text(window->RPort, "Click the close gadget to exit.", 31);
/* Message loop */
while (!done) {
Wait(1L << window->UserPort->mp_SigBit);
while ((message = (struct IntuiMessage *)GetMsg(window->UserPort))) {
class = message->Class;
ReplyMsg((struct Message *)message);
if (class == CLOSEWINDOW) {
done = TRUE;
}
}
}
/* Clean up */
CloseWindow(window);
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)IntuitionBase);
return 0;
}
This program demonstrates several key Amiga programming concepts:
Library Management: Opens the Intuition and Graphics libraries, which are essential for GUI operations and drawing.
Window Creation: Creates a window with standard gadgets (close, drag, depth) using Intuition's windowing system.
Graphics Operations: Uses the Graphics library to draw text in the window with SetAPen(), Move(), and Text() functions.
Event Handling: Implements a proper message loop that waits for window events and responds to the close gadget.
Resource Cleanup: Properly closes the window and libraries when exiting.
To compile this on an Amiga system with SAS/C or similar compiler, you'd typically use:
sc hello.c LINK
The program opens a draggable window titled "Hello Amiga!" and displays greeting text. Users can close it by clicking the close gadget, demonstrating the cooperative multitasking nature of AmigaOS.