Programming AmigaOS in C

Other Useful Tips

a) Adding a version string to your program.

Any program or library in AmigaOS should have a version string attached to it. The version string can then be view via the Info (or Information) menu entry in Workbench or the 'version programname' command.
To add a version string, add the following line somewhere at the top of your program code.

const char __ver[40] = "$VER: program_name version_num.sub_version (";

For example,

const char __ver[40] = "$VER: MyGraphicsProgram 2.1 (15.11.2015)";

b) Using ESC printer type commands when printing to console.

You can use AmigaOS printer type ESC sequences to control formatting of text to the console. Just replace *E (Esc) with \x1b.
For example, the code to clear the screen is Esc[0;0HEsc[J, the code for the printf string would be:

printf ("\0x1b[0;0H\0x1b[J");

To display text in colour, you can use Esc[nnm where n=30-39 for a foreground colour or 40-49 for background colour.
Use Esc[0m for normal text. Just replace *E (Esc) with \x1b.

printf ("\0x1b[32mRed Text\0x1b[0m");

c) Reading CPU and Cache information.

You can find out what CPU you have by reading the AttnFlags from Exec Library's ExecBase, and determine the CPU by AND'ing the flags
withe the appropiate mask for each CPU (see execbase.h headers). Instruction and Data Cache, Burst and Copyback modes can be read and modified
using Exec's CacheControl() function.

/* Read attention flags incl. cpu info */
UWORD flags = SysBase->AttnFlags;

/* Read current cache flags from system */
ULONG currbits = CacheControl (01, 01);

Message Ports