Fixing a bug in FOCAL-11

60 views
Skip to first unread message

Eric N

unread,
Sep 13, 2026, 12:02:56 PMSep 13
to [PiDP-11]
I have been tricking out my RSX-11M-PLUS system on my PiDP-11, and was filling the system with all of the essential programming languages used throughout the era like C, FORTRAN, COBOL, LISP, BASIC, and FOCAL.  

FOCAL is an interpreted language similar to BASIC and was created in the late 60s.  Lunar Lander was originally written in FOCAL.  I thought it would be fun to install it, and run a few programs, so I compiled FOCAL-11 from the DECUS archives (DECUS RSX87A collection, directory 312315), and found a FOCAL programming guide (DEC-08-AJAB-D PDP-8-I FOCAL Programming Manual.), and typed in a random program.

It just so happened my random program exposed a bug in FOCAL.  FOCAL-11's e^x routine has a recursion error.  The FOCAL-11 function call is XFEXP and if you use it, it will recurse forever and crash the stack.  I looked at similar functions, and they all have recursion depth guards in them, so I applied the same guardrails to XFEXP.  As far as i can tell, this was the only function that was missing the recursion check.

This fix is in FCLMAI.MAC, and the complete FOCAL-11 source code is attached.  I've bumped the FOCAL version to V11-01C.  Here is how to compile and run it:

1. FTP or get your FOCAL-11 source code onto your PDP-11.  My code resides on DU1:[FOCAL]
2. SET DEFAULT DU1:[FOCAL]
3. SET /MCR=TI:
4. MAC FCLMAI=FCLPR,FCLMAI
5. MAC FCLINI=FCLPR,FCLINI
6. SET /DCL=TI:
7. TKB @FCLBLD.TKB

This produces FCL.TSK
RUN FCL.TSK

You can type in this program to see FOCAL in action and confirm the bug fix (program will crash if bug fix not applied):
  1.03 ASK "SINE WAVE AMPLITUDE: ", AMPL, !
  1.04 ASK "DAMPING FACTOR COEFFICIENT: ", T, !
  1.05 FOR K=0,60; TYPE "."
  1.06 TYPE !; FOR I=0,.5,15; DO 1.11; TYPE "*"; DO 3
  1.07 QUIT
  1.11 FOR J=0,30+AMPL*FSIN(I)*FEXP(-T*I); DO 2; T " "

  2.10 IF (J-32) 2.3, 2.2, 2.3
  2.20 TYPE "."
  2.30 RETURN

  3.10 IF (31-J) 3.3, 3.2; FOR K=J,30; TYPE " "
  3.20 TYPE "."
  3.30 TYPE !; RETURN

Type GO to run the program and you will see your cool damped sine wave!
*go
SINE WAVE AMPLITUDE: 15

DAMPING FACTOR COEFFICIENT: .135

.............................................................
                              * .
                                .     *
                                .          *
                                .           *
                                .         *
                                .     *
                                *
                           *    .
                        *       .
                       *        .
                       *        .
                         *      .
                             *  .
                                *
                                .  *
                                .    *
                                .    *
                                .  *
                                *
                              * .
                            *   .
                           *    .
                           *    .
                            *   .
                             *  .
                              * .
                                *
                                *
                                . *
                                *
                                *

Here are some helpful FOCAL commands:
Save a program like HELLO.FCL
* L O HELLO.FCL <--L O = LIBRARY OPEN)
* L W A <-- (L W = LIBRARY WRITE, "A" = ALL — writes the whole program)
* L C O <-- L C O = LIBRARY CLOSE OUTPUT)

Load a program
* @HELLO.FCL

Exit FOCAL
Ctrl-Z

Enjoy,
Eric N.
FOCAL-RSX11-v11-01C.zip
Reply all
Reply to author
Forward
0 new messages