In this post I explore the Action! directives. Directives are commands that are executed at compile time instead of run time. Basically when the program is being compiled. Action! has three directives:
- INCLUDE – This allows you to pull additional program code from other disk files to be compiled along with the program currently being compiled. This is easy to use. Just add the filename you want to include in quotes following the INCLUDE directive:
INCLUDE "D4:LIB.ACT"
- DEFINE – This allows you to create a constant name that can be used throughout the source code to reference a pre-defined value. At compile time the name is replaced by the value throughout the code (except when the name appears in quotes). This can be extremely useful for avoiding “magic numbers”, and for defining things that might need to change between compilations. To use it you specify the name you want to use in code, followed by an equal sign, followed by the value you want it to have (in quotes). Example:
DEFINE cYES = "1" DEFINE cNO = "0"
- SET – This is used to modify a memory location. I’m still trying to determine a use-case for this directive. It could be used to set the left margin to 0 for example. But if the program needs that setting, it should be done inside program code with a Poke. The difference is that SET is executed at compile time, and from inside program code it executes at run time. Having it execute it run time guarantees it executes each time the program is run.
The INCLUDE directive is especially useful for breaking large code bases down into more manageable chunks, typically related functions and procedures. Two particularly useful INCLUDES are for the Action! Runtime library (which lets your program run without the Action! cartridge installed), and the Action! Toolkit libraries. I’ll briefly touch on both.
Toolkit
The Toolkit has many useful functions. One that is particularly useful is the enhanced PrintF and PrintFD. These two function more like the C and Perl equivalents with the ability to set field lengths and justification. The Toolkit is divided into sections with each section having a number of routines that are related. Sections include:
- ABS – Single routine to compute the absolute value of an INT
- ALLOCATE – Several routines for manipulating memory allocation at runtime
- CHARTEST – Several routines for testing and converting characters (bytes) such as IsDigit, ToUpper, etc
- CIRCLE – Single routine to draw a circle
- CONSOLE – Single routine to debounce the console keys and connect routines to them
- IO – Several routines for advanced IO such as file rename, lock, etc; and binary get/put routines.
- JOYSTIX – Several routines for working with the joysticks
- PMG – Several routines for working with player missile graphics
- PRINTF – Single routine that provides an enhanced PrintF and PrintFD
- REAL – Several routines for working with floating point numbers
- SORT – Several routines for sorting different data types
- TURTLE – Several routines that mimic Turtle Graphics commands
To include a toolkit section as part of your program, simply INCLUDE it at the beginning:
INCLUDE "D:PRINTF.ACT"
Runtime
Normally when running an Action! program the cartridge must be installed. The compiled program needs the cartridge at run time for the library routines (like Print, etc). Including the Action! Runtime library in your program basically compiles equivalent library routines of the cartridge directly into your program, there by freeing your program from the restriction of needing the cartridge. If you plan on distributing software written in Action! you will undoubtedly compile with the Runtime library.
To include the runtime as part of your program, simply INCLUDE it at the beginning:
INCLUDE "D:RUNTIME.ACT"