Omikron BASIC for Apple Power Mac

3. The Menus of the Editor Contents | 5. The Command Set: & to @

Chapter 4


User Interfaces

Programs with Graphical User Interface
Programs without Graphical User Interface

Commands and Syntax

Basic Commands
Explanation of Syntax
About the Examples
Further Explanations

Variable Types



Mathematical Operators
Comparison Operators
Pointers and Address Operators
Priority of the Operator

User Interfaces

Omikron Basic offers two basic options for writing programs:

Programs with Graphical User Interface

The use of graphical objects such as menus, dialog boxes, and windows applied to communicate between program and user constitutes a graphical user interface. Today, basically all commercial programs requiring a user interface offer such a graphical user interface. Use the EasyGem Library enclosed with Omikron Basic to program graphical user interfaces for your programs. Theoretically, it is also possible to directly call the corresponding MacOS toolbox functions using the MAC_OS command. However, this is considerably more complex than using the EasyGem Library and only sensible for special cases.
Larger projects or programs to be used by others should offer a graphical user interface since this significantly simplifies use of the program.

Programs without Graphical User Interface

Contrary to many other modern BASIC implementations, Omikron Basic makes it possible to write small, compact programs without graphical user interface as well. Commands such as INPUT and PRINT are used for input and output. Such programs are especially well suited to quickly try out the commands discussed in the next chapter when learning how to use Omikron Basic or to just write a small program for a specific task where previously no standard software was available or handy at the moment.
You should always use the Omikron Basic output windows for this task (to be discussed now) to make sure that your programs still run clean within the multitasking environment of the MacOS.

The Omikron Basic Output Windows

Upon request, Omikron Basic makes so-called output windows available. These windows can be used to hold all output, which would otherwise be rerouted directly to the screen. The management of these windows is performed automatically by Omikron Basic. Consequently, programs that have no window management and use PRINT and INPUT for input and output run neatly in a multitasking environment as well. The Omikron Basic output window can be activated with the command COMPILER "OUTPUT_WINDOW X*Y" - the maximum values for X (width) and Y (height) to be applied to the first window have to be in pixels. The contents of the output windows are buffered in the application heap of the program. Therefore, depending on size and pixel depth, memory must be sufficiently available. Where appropriate, more memory has to be reserved for the program using the finder or COMPILER PRE_SIZE X."

If the output windows are active, a menu bar is also added, which allows easy access to the Apple menu at the left as well as the help and program menu at the right side. In order to make sure that Omikron Basic receives the event messages concerning the output windows or the menu bar, the command COMPILER "EVENT" should be used to cause a WaitNextEvent call is compiled into the program at the appropriate location. See also the demo program 'Mandelbrot.BAS.'
If a program is running an INPUT or INPUT$ instruction, WaitNextEvent calls are always made to the MacOS, because key pressings are constantly observed. The same applies to the FORM_ALERT command.
The output windows also have scroll bars so that they can be designed larger than the physical screen. However, please consider that the window contents must be buffered in the application heap. A window with 1280 x 960 image pixels requires in the case of, e.g., 256 colors, 1.2 MB of storage.
The increments used to scroll the window content if clicking on the arrows on the slider bar can be adjusted with the procedure Set_Scroll_Parameter from the Extension Library.

Note: With the command SCREEN, additional Omikron Basic output windows can be opened.

The Menu of the Omikron Basic Output Windows

If the Omikron Basic output windows are activated, an additional menu bar is created. A few basic functions can now be called using the menu 'File.'

Open ...
The uppermost Omikron Basic output window is loaded with a file previously created with 'Save as ... ' If the picture to be loaded has other dimensions or another pixel depth, it is adapted automatically to the Omikron Basic output window. The file must be available in the 'PICT' format. Thus, it can also be modified by other programs.

Save as ...
The content of the buffer for the uppermost Omikron Basic output window is stored in the 'PICT' format. Consequently, it is possible to load and further process the stored image by other programs.

Page Setup ...
The layout dialog box opens. The printer settings can be adjusted in this dialog box.

Print ...
The print dialog box opens. Further adjustments can be effected in this dialog box. The buffer for Omikron Basic is displayed in the output window after 'OK' has been clicked on.

The program is terminated. If only one window is left open, clicking on the closer in the Omikron Basic output window has the same effect. First, however, a security query is issued.

Commands and Syntax

BASIC Commands

The Omikron Basic editor accepts a whole series of BASIC commands, which are remainders from previous versions and, among other things, were used there for controlling the old editor and the old interpreter. Now, these functions are either carried out by the editor itself (e.g., LIBRARY, DEFINT, RENUM, etc.) or they have lost any practical application purpose because of the new user interface. Others are also typical interpreter commands, which were already always ignored by the compiler because of that. Others in turn used specific properties of ATARI hardware or of the ATARI operating system and are therefore unimportant for the MAC.
To keep compatibility problems with older programs to a minimum (most often it already suffices if the said commands are simply ignored), Omikron Basic is programmed so that the editor also understands invalid commands; however, these are skipped by the compiler.
The insignificant commands are displayed in gray in the chapter 'The Command Set'. These keywords cannot be used by the user for his or her purposes.

Explanation of Syntax

Information in angle brackets <...> is to be replaced by the corresponding expression.
Information in square brackets [...] is, depending on the desired application, an addition that could be left out.
Two square brackets [[...]] set around an expression mean that this expression, depending on the application, can be left out or appear once or several times.
Information in braces {...|...} represents a selection, from which the user is supposed to select one of the two options separated by the bar "|".

About the Examples

Many of the commands are accompanied by short example programs that are displayed in a field with a light yellow background. Most of these programs can be typed in or more easily copied from the online manual and then pasted directly into a program window. However, in many cases some compiler control words must still be placed in order to receive a compileable program (see the Mandelbrot.BAS program in the DEMO folder). In the case of some programs, functions from the Extension Library are also used. In these cases, the Library must be loaded subsequently from within the editor using 'Merge Library ...' and integrated into the program.
The monitor results are shown below in a somewhat darker yellow color, provided it is not a question of graphics, etc. In these cases, behavior of the program is described in a written format.

Further Explanations

<Num. Expression>
A numerical expression is any term supplying a numerical result. In this case, the type is unimportant (integer, simple or double precision). The compiler performs an automatic type conversion during translation. If, however, a command, for example, always expects only an integer type, care should be taken always to pass only integers.
Consequently, the compiled program becomes shorter and faster.

<String Expression>
An expression of the type string.

<File Name>
A file name is a string containing a FileSpecificationRecord and has the following construction:
2 byte VolumeReferenceNumber or 0, if unknown.
4 byte DirectoryIdentificationNumber or 0, if unknown.
1 byte length of the subsequent file name, file path, or partial path.
1-63 bytes file name, file path, or partial path.

A file can be specified on the Macintosh in different ways. If the VolumeReferenceNumber and the DirectoryIdentificationNumber are known, they also should be indicated without fail because absolute non-ambiguity is only guaranteed through them. However, it is also possible to identify a file via a pathname. In this case, the individual folders must be separated with a colon. The actual file name is at the end. (E.g., "MacintoshHD:Omikron Basic:DEMO:Mandelbrot.BAS"). To build a FileSpecificationRecord it is best to use the Get_Fsspec$ function from the Extension Library.
If data about the volume or directory are missing, then the path name has to be indicated in its entirety - if the desired file is not located in the current directory. Otherwise, it is sufficient to indicate partial paths, and write a colon as the first letter of the partial path. In this case you simply set the VolumeReferenceNumber and the DirectoryIdentificationNumber to zero and indicate only a partial path with a preceding colon or a file name without a colon. The program will search for the file in the partial path starting at the current path.
In order to find out the current VolumeReferenceNumber and DirectoryIdentificationNumber, you can use the procedure
Get_Cur_Dir from the Extension Library.

<Num. Variable>
Numerical variables no matter what type. In individual cases, only simple variables and no fields are maybe permitted.

<Return Variable>
Returns the result value of a command or function. In the case of INPUT USING it is a kind of termination condition.

The values passed to a function or procedure. If using CALL, a passing as a long integer can be effected if prefixed by "L".

<Bit Number>
Unsigned number between 0 and 31. The weight of the corresponding bit is 2^<bit number>

<Integer Variable>
Integral variables (word=16 bit or long=32 bit); field variables are also permissible.

<Memory Address>
32 bit broad long integer number specifying a specific storage cell.

A label or flag determines a specific location within a program. It can consist of any characters allowed for variables. A label can be:

1. A specific line:
If line numbers are used, it is possible to reach a specific line by naming its number. The line number can also be computed, that is, any numerical expression can be used as a label. If, however, the expression consists of only one numerical variable, this variable has to be set within parentheses to prevent being confused with a label.

2. A specific program label:
In every location of the program a label can be identified using "-<identifier>". The identifier may contain all characters authorized for variable names (all alphabetic characters, digits, "_" and the characters 128 to 255). Referring to such a label, it is simply a question of using the identifier; the prefixed minus character is not used. It is also possible to name the label via a string expression. It has to contain the identifier of the label and should not be longer than 8 characters, because the compiler uses only the first 8 characters for an identification evaluation. (This is only valid if the label is accessed via a string expression.)

In general, it is recommended to refrain from using numerical or string expressions for line numbers and/or labels because these have to be first evaluated during runtime and this will slow the execution of the program.

Drive stands for a volume (e.g., fixed disk, CD-ROM, or floppy disk) and can have any name followed by a colon.

Any angle information passed to graphics commands should always be in 1/10 degrees. For example, 900 corresponds to 90 degrees.

<File Number>
An unsigned number between 1 and 16. The number has a fixed connection with the corresponding file (see OPEN). All commands and functions affect the file, which has been allocated to the file number using OPEN.

Variable Types

Omikron Basic offers a whole line of different variable types, which are useful for different purposes. In the interest of a speedy program, only integer variables should be used - if possible - if only integers can be considered as variable values. Because strings are especially complicated, they should be avoided if at all possible.

Variable names can be created almost anyway the user desires. One variable name can also be used several times in the same program as long as different postfixes are used (meaning different value ranges). They are managed completely independent from one another. The postfix takes care of that. The ASCII characters 48-57, 65-90, 95, 97-122, and 128-255 are permitted as variable names. However, the names cannot begin with a number, otherwise BASIC cannot keep them apart from constants.

The characters starting at 128 can be accessed in different ways:

1. With a pre-selection key. First, F1 has to be pressed, and then a normal character is entered. Because of F1, 64 is added to this ASCII code. The same can be done with F2; the only difference is that 128 are added.

2. With the depressed ALT key, it is possible to enter the ASCII code of the character directly via the keypad keys. As soon as the ALT key is released or 3 digits are entered, the desired character appears on the screen.

3. The country-specific special characters can be accessed by pressing a combination of modifier keys and normal keys.

Thus, it is possible now to write, for example, 

Length = Height * SIN(ß)

A suitable font is presupposed.

See also ASCII Codes.

The variable A shall serve as an example. Omikron Basic distinguishes every individual variable from every other one, even if they are all called A. The postfixes for each individual variable already differentiates them. If the variable A%L has already been used, it is still possible to use the independent fields A%L(1) and A%L(1,2) . The difference consists here of the dimension of the fields. However, it is better to avoid such name similarities, otherwise, a program can become unclear very fast.
Incidentally, it is also possible to allocate a standard variable type for each first character permitted to be used as a variable character. Each variable beginning with this letter has then automatically a different standard variable type, unless the postfix of another variable type is explicitly named. (See also Mode/Settings>Program.)

The following variable types are possible:

Integer (whole number)

Integer numbers are whole numbers, that is, numbers without decimal places. Their number range is limited to the values indicated below. The advantage of integer numbers is their fast processing and that there are no rounding-off errors.

Long Integer: Computation Range: -2147483648 to +2147483647
  Memory Requirement: 4 bytes (= 4 characters)
  Postfix: %L e.g., A%L, A%L(1)
Word Integer: Computation Range: -32768 to +32767
  Memory Requirement: 2 bytes (= 2 characters)
  Postfix % e.g., A%, A%(1)
Byte Integer: Computation Range: 0 to 255
  Memory Requirement: 1 byte (= 1 character)
  Postfix: %B e.g., A%B(1)
Flag / Boolean: Computation Range: "false" (0) and "true" (-1)
  Memory Requirement: 1 bit (= an eighth of a character)
  Postfix: %F e.g., A%F(1)

Note: The variable types 'Byte Integer' and 'Flag / Boolean' can only be used in fields and not as independent variables.

Float (Floating Point)

Floating point numbers are numbers with decimal places. Their number range is (almost) unlimited since they have an exponent of 10. If the number range of the fraction is not sufficient, each exponent is increased by one, and the fraction is shifted one place to the right. The greater the number, the more inexact it is as well. However, the number of digits always remains identical. For example, a floating point number looks like this:
123.45678 times 10 to the 2nd power
Fraction Exponent
Advantages of these numbers are the decimal places and that the precision adapts to the order. Disadvantages are the rounding-off errors possible with floating point numbers. One third (1/3) is without doubt still something different than 0.333333333333333. Not all real numbers can be exactly represented by a float number. Since the PowerPC has a very powerful floating point computation unit, these types of numbers can have an even greater computation speed than integer numbers.

Single Float: Computation Range: +/-1.4x10^-45 to 3.4x10^+38
  Precision: 7-8 places
  Memory Requirement: 4 byte (= 4 characters)
  Postfix: ! E.G., A!, A!(1)
Double Float: Computation Range: +/-4.9x10^-324 to 1.8x10^+308
  Precision: 15-16 places
  Memory Requirement: 8 byte (= 8 characters)
  Postfix: # e.g., A#, A#(1)

String (Character String)

A string is a character string, that is, a text of up to 2147483648 characters in length. The text can contain any characters from 0 to 255. Strings are managed very effectively by Omikron Basic, which results in a very high processing speed when comparing to other BASIC variants. The length of a string can change during the running of the program (dynamic string management). Thus, strings do not have to be dimensioned in Omikron Basic as they have to in many other BASIC dialects and programming languages.
Strings should only be used if the problem cannot be solved equally well using integers because in spite of the highly optimized management of strings, their use is never as fast as the work with integers.
For example, if only one letter is needed, it is more practical to allocate the corresponding ASCII value to a integer variable (see ASC) and then to work with it instead of using the letter, especially when working with loops with a high execution rate.

String: Memory Requirement: 16 bytes (= 16 characters) plus the length of the string.
  Postfix: A$ e.g., A$(1)


Constants are numbers, which do not change, that is, they are not variables. But they too have a type, which corresponds to the variable types and is dependent on spelling and the value of the constants:

123 Short Integer
35000 Long Integer
123. Double Float
1.3 Double Float
1E20 Single Float
123! Single Float
123# Double Float
1D20 Double Float
1.23456789 Double Float
"hello" String

A number containing one of the following characters is automatically a floating point number:
. ! # E D
The postfixes ! and # can therefore also stand behind numbers.
The letter E stands for "Exponent Ten" of a single floating number and D for " Exponent Ten" of a double floating number.


Omikron Basic offers a great number of operators, which are discussed in the following according to the organization of their function groups.

Mathematical Operators

Character: Meaning:
+ Addition
- Subtraction
* Multiplication
/ Division
^ Raise to a power
+= Addition with allocation
-= Subtraction with allocation
*= Multiplication by allocation
/= Division with allocation
\ Integer division: Provides the result of a division rounded off to the nearest whole number
MOD Modul operator: Provides the rest of a whole number division

Comparison Operators

Omikron Basic offers the following comparison operators:
larger as
< smaller as
= equal
>= larger or equal
<= lesser or equal
<> unequal

Pointers and Address Operators

"&" determines the address of a variable, field or function.

"*" accesses an object (de-references it). The pointer variable must follow the operator. The type definition also still has to be indicated here with a postfix - just as in the case of a normal variable. In the special case of a pointer aiming towards functions, using "*" calls the function at which the pointer variable is aiming.

Priority of the Operators

All operators
listet here are explained in detail in Chapter 5 and listed according to priority of the operators. The operators shown more at the top have a higher priority than the ones at the bottom. Operators in the same line have equal priority.

( , ) (parentheses) (highest priority)
& (address operator), * (pointer operator), FN (function)
NOT, +, - (sign)
(raise to a power)
*, /
\, MOD
+, -
<, <=, >, >=, <>
(lowest priority)

Example: PRINT -3^2, (-3)^2, 3*1 SHL 2, (3*1) SHL 2
Result: -9 9 12 12
Example: PRINT -1>=2 OR 1<2, -1>=((2 OR 1)<2)
Result: -1 0

3. The Menus of the Editor Contents | 5. The Command Set: & to @

Support | Order | Start | Home:

© 1997-2001 Berkhan-Software