Computing: DOS, OS/2 & Windows Programming

Exotic programming languages for DOS: Focal-81.

"FOCAL (acronym for Formulating On-line Calculations in Algebraic Language, or FOrmula CALculator) is an interactive interpreted programming language based on JOSS and mostly used on Digital Equipment Corporation (DEC) PDP series machines. JOSS was designed to be a simple language to allow programs to be easily written by non-programmers. FOCAL is very similar to JOSS in the commands it supports and the general syntax of the language. It differs in that many of JOSS' advanced features were removed to simplify the parser and allow the system to run in less memory. Some of the reserved words (keywords) were renamed so that they all start with a unique first letter. This allows users to type in programs using one-character statements, further reducing memory needs. This was an important consideration on the PDP-8, which was often limited to a few kilobytes".

The paragraph above is how they describe the FOCAL programming language in Wikipedia. And continuing: "Like JOSS, and later BASICs, FOCAL on the PDP-8 was a complete environment that included a line editor, an interpreter, and input/output routines. The package as a whole was named FOCAL-8, which also ran on the PDP-5 and PDP-12. When ported to the PDP-11, the resulting FOCAL-11 relied on the underlying operating system, RT-11, to provide file support and editing. The language definition was updated twice, to FOCAL-69 and a very slightly modified FOCAL-71. A port to the Intel 8080 was also available.

This tutorial is about the installation of Focal-81 for x86, written in 2013 by Marian Mirzojan, on MS-DOS 6.22. The software also works on FreeDOS, and the tutorial should apply to other DOS platforms, too.

You can download the software from the Vetusware website. The download archive contains the program’s folder structure. I extracted the files on my Windows 10 and copied them to a floppy diskette. On my MS-DOS machine, I copied the files to a newly created directory, that I called "focal81". Supposing that the actual directory is C:\ and that the files are in A:\
    mkdir focal81
    cd focal81
    a:
    copy *.* c:

The screenshot shows the content of c:\focal81.

Focal-81 on MS-DOS 6.22: Content of the installation directory

The executable is called focalx86.exe. It starts an interactive programming environment, very similar to the one, that (if you are old enough) perhaps remember from the first BASIC implementations. At the "*" prompt, you can enter FOCAL commands, either one per line, either several per line, using the semicolon (;) as separator. If the command(s) is (are) correct, it is (they are) immediately executed. Some examples are shown on the screenshot below.

Focal-81 on MS-DOS 6.22: The interactive programming environment

Some notes concerning the commands shown on the screenshot:

Focal-81 programs (usual file extension: .foc) are made of a sequence of statement lines, one statement per line, or several statements separated with a semicolon. Each line must start with a line number. FOCAL line numbers are special: they are made of two 2-digits numbers, separated by a period. The first 2-digit number is the line group, the second one the line number within this group. This is a rather interesting feature, as it allows to easily apply commands to a single line, or to a group of lines. Examples: do <line-number> executes a single line of code, then returns, whereas do <line-group> executes all lines of code for this group before returning. Other example: erase <line-number> deletes one line of code from a program, erase <line-group> deletes all lines of this group.

As in similar BASIC environments, we can type in a program, when being in the interactive development environment. All we have to do is to enter the commands, preceded by a line number. Here is a dummy program printing "Hello, World!" 5 times. It shows, how to call a subroutine, using the do command.

    10.10 for x = 1,5; do 20
    10.20 quit
    20.10 type "Hello, World!", #, !

Note that there is a return command, that may be used to return from a subroutine. We normally don't need it, as do <group-number> executes all statements of the group, and then automatically returns. Also note, that in this context, the quit command terminates the program, not the Focal-81 development environment.

To execute the program, use the command goto (unconditional jump to the beginning of the program). It has become practice to use go instead.

The screenshot shows the code of our little program (entered before), and the execution of the program.

Focal-81 on MS-DOS 6.22: Entering and running a simple program

To save a program to disk, use the command library save <filename>. Note that you have to specify the filename without enclosing quotes.

To load a program from disk, use the command library call <filename>. Again, no enclosing quotes for the name of the file.

Similar to the BASIC command list, we can use the FOCAL command write to display the program code, or part of it. Used without parameters, the command lists the entire program, used with a line number or a line group, it lists this specific line, respectively all lines of this group.

I already mentioned the erase command used with a line number, or a line group. Used without parameters, the command erases all variables. The command erase all deletes the entire program.

Besides the command go to run the program from the beginning, you can use do <line-group> to execute a subroutine, and goto <line-number> to start the program beginning with the code in a given line. For our program hello.foc, for example, the commands do 20 and goto 20.10 are both valid, and display once the text "Hello, World!".

To enter data form the keyboard (this seems to work with numeric data only?), use the command ask <prompt>, <variable1>, <variable2>, etc. This is similar to the BASIC input command. The prompt has to be enclosed in double quotes, of course.

There is one important command, that I haven't yet described: if. Its usual form is the following:
    if (<expression>) <line-number-negative>, <line-number-zero>, <line-number-positive>
This statement means: if <expression> less than 0, go to <line-number-negative>; if it is equal to 0, go to <line-number-zero>; if it is greater than 0, go to <line-number-positive>.

Two other forms of the command are possible:
    if (<expression>) <line-number-negative>, <line-number-zero>; <command>
    if (<expression>) <line-number-negative>; <command>
The first statement means: if <expression> less than 0, go to <line-number-negative>; if it is equal to 0, go to <line-number-zero>; if it is greater than 0, execute <command>. The second statement means: if <expression> less than 0, go to <line-number-negative>; if it is greater than or equal to 0, execute <command>.

The original FOCAL language included some further important commands, that actually aren't implemented in Focal-81, in particular the possibility to work with files, and a (rather simplistic) conversion of string input to a number. Another command, that is missing in Focal-81 is modify, corresponding to the BASIC command edit, and allowing to edit the code of a given line.

To terminate this article, here is the Focal-81 code of the classic "Guess the number" game.

    10.10 type #, !, "GUESS THE NUMBER GAME.", #, !
    10.20 set n0=fitr(100*fabs(fran(0)))
    10.30 if (n0) 10.20, 10.20, 10.40
    10.40 set count=0
    10.50 do 20
    10.60 type #, !
    10.70 quit

    20.10 ask "Enter number? ", n
    20.20 set count = count + 1
    20.30 if (n-n0) 21.10, 23.10, 22.10
    21.10 type "Your number is too small!", #, !
    21.20 goto 20.10
    22.10 type "Your number is too big!", #, !
    22.20 goto 20.10
    23.10 type "You have found the number with ", %0.0, count, " guess(es).", #, !
    23.20 return

Note: The function fran generates a series of numbers between -1 and 1. The function must take an argument, that seems, however, have no effect on the numbers generated (?). To note that the number series is always the same (?), thus not really adequate for random-based game programming.

The screenshot shows the load of the source code and the execution of the program.

Focal-81 on MS-DOS 6.22: Loading and running a program

If you find this text helpful, please, support me and this website by signing my guestbook.