next up previous contents
Next: A Note on C++ Up: Cryptic Allusion KallistiOS / Previous: Getting Started   Contents

A Basic KOS Program

A KOS program is pretty simple and straightforward. Each C module should include kos.h as a system header (e.g. ``#include <kos.h>'').3.1You should have a C-standard ``main'', which is called main. It is also possible to use several directives outside your main function that modify the initialization and shutdown behavior of KOS. It should be instructive to follow along in one of the Hello World examples for your platform to see how a basic KOS program should look.

You can have KOS automatically initialize subsystems if you want them to be active during your program. For example, you will probably want IRQs to be active in your program. On the other hand, you might not want threading active.3.2A basic KOS init flags line looks like this:

KOS_INIT_FLAGS(INIT_DEFAULT);

The parameter is a bitmask describing what you want to be initialized by default. The constant INIT_DEFAULT is available on every platform as a generic way to initialize as much of KOS at once as is feasible. For example, on the DC, this constant enables IRQs and pre-emptive threads.

Another directive available to you is the romdisk directive. It looks like this:

KOS_INIT_ROMDISK(romdisk);

The parameter is a pointer to a ROMFS image created by genromfs. ROMFS was taken from Linux (the specification, not any code) and the Linux and KOS implementations are 100% compatible, except that KOS doesn't implement a few ROMFS features such as hard links and soft links. You can, for example, mount the same ROMFS image in KOS and under a loopback device in Linux. If you don't want a ROMFS, then you should use the constant ROMDISK_NONE. ROMFS images are generally included in the binary by using the KOS utility bin2o, which is included in the ``utils'' tree. The Hello World Makefiles show how to do this.

Note that leaving out either of the above init lines will cause KOS to use defaults. KOS_INIT_FLAGS defaults to using INIT_DEFAULT for its flags, and KOS_INIT_ROMDISK defaults to NULL (no romdisk).

By the time your main function is called, the basic KOS systems should be ready to go! If you want to use any of the extra/add-on libraries that come aggregated with KOS, then you will need to initialize them seperately. These might include 3D support, an MP3 or OGG playback library, KGL, etc.

For more info on the different subsystems, please see the chapter devoted to that system. For examples, see the ``examples'' directory off the KOS root.

Now that you know what a basic KOS program looks like, you'll probably want to start figuring out how to use the various parts of the library. The following chapters are more in the way of a reference manual than a tutorial. The next chapter describes the portable parts of KOS which are present on every platform (though in some cases there are minor differences). The chapters after that describe the various platform-specific parts of KOS, and the final chapters describe the add-on libraries which are aggregated with the KOS distribution.



Subsections
next up previous contents
Next: A Note on C++ Up: Cryptic Allusion KallistiOS / Previous: Getting Started   Contents
Dan Potter 2002-07-29