Subject: Re: The FOCAL interpreter - more problems

From: [email-masked] (Crystobal J. Junta)
Date: 1 Nov 1993 12:27:13 GMT

Since it has been established that there are problems with
1. Line numbering
2. Functions (or lack thereof)
3. Parenthesis
4. I/O,
perhaps we should define some sort of FOCAL standard - I think we as FOCAL fans
at this time have the ultimate authority to do so.  Some feel that we have to use
FOCAL 1969 as a standard.  Well, then would anyone please post an accurate
description of 1969 language before each of us starts hacking the interpreter in
question to extend it our own way.

Also, a question - what are the decent pdp8 emulators, and where can I find one?

-C.J.Junta

---

From: jones@pyrite (Douglas W. Jones,201H MLH,3193350740,3193382879)
Date: Mon, 1 Nov 1993 15:09:43 GMT

>From article <[email-masked]>,
by [email-masked] (Crystobal J. Junta):

> ....                       Well, then would anyone please post an
> accurate description of 1969 language before each of us starts
> hacking the interpreter in question to extend it our own way.

What follows is a uuencoded copy of the FOCAL 1969 paper tape.  To use
it, you need a PDP-5, or any model of PDP-8, with 4K of memory, a paper
tape reader (high or low speed) and a BIN loader.  An emulator that can
emulate a paper-tape reader will do just as well as the real machine.

This tape consists of two consecutive BIN format load images, preceeded,
followed, and separated by binary leader.  To load it into memory, start
by loading the BIN loader, then mount the paper tape on the appropriate
tape reader (high speed or low speed reader, depending on how your BIN
loader is configured), and then:

Start the bin loader.  It will stop after loading image number 1.

Start the bin loader again.  It will stop after loading image number 2.

Start the program at address 0200.  It will begin with a dialog asking
you whether you want to keep the trig functions or turn the space they
occupy over to more user code.

(Note that, being a core memory machine, FOCAL stays loaded once you
load it, whether the power fails or not.  Most FOCAL users would only go
through the above once in a blue moon.

---

From: [email-masked] (Magnus Olsson)
Date: Mon, 1 Nov 1993 15:53:22 GMT

In article <[email-masked]>,
>emulate a paper-tape reader will do just as well as the real machine.

Could anybody please recommend such an emulator for Unix? I've seen
lots of emulators around, but not being acquainted with the real thing
I have some difficulty deciding which of them are good and which
aren't. 

              Magnus Olsson                | \e+      /_
    Department of Theoretical Physics      |  \  Z   / q
        University of Lund, Sweden         |   >----<           
 [email-masked],  [email-masked]  |  /      \===== g
PGP key available via finger or on request | /e-      \q

---

From: [email-masked] (Jon Krueger)
Date: 1 Nov 93 20:59:19 GMT

Charles Lasner writes:

> Perhaps we need a definitive spec for just what FOCAL actually is.

I can see it now ... ANSI FOCAL :-)

-- Jon

--
Jon Krueger  [email-masked]    The intention was not omissional.

---

From: [email-masked] (Charles Lasner)
Date: 4 Nov 1993 15:22:08 GMT

In article <[email-masked]>,
Greg Ewing <[email-masked]> wrote:
>
>Where can one get this from? I have a crazy idea for an adventure
>game with an embedded fully-functional PDP-8, and a genuine language
>implementation from the period would be just the thing to go with it.
>
>Are there any other pieces of PDP-8 software around? A BASIC and/or
>operating system would be neat.

All of the PDP-8 items requested are in the process of being added to sunsite.
The only problems left (other than cranking it out into files of appropriate
formats and all the other librarian-type stuff, etc.) is that unless you
already have a bootable PDP-8 system, it's difficult to get one up, unless
someone mails you the relevant media.

I have solved the problem of getting Kermit-12 up though:  Assuming you have
an OS/8 system up already, you use ODT to type up some short programs that
you then use to download the Kermit-12 binaries from a (cross your fingers!)
clean connection, such as a null modem to another machine, etc.  The result
is a starter version of Kermit-12 which is robust enough to use to get the
rest of the files, etc.

But without snail mail help, some people are stuck to get started (unless
they are going to emulate the whole thing!).

cjl

---

From: [email-masked] (Charles Lasner)
Date: 4 Nov 1993 15:41:44 GMT

>> hacking the interpreter in question to extend it our own way.

It's real dangerous to have some revisionist version of a FOCAL-like
language because each quirk really matters.  It's even more serious than the
differences you find in C implementations, etc.

>followed, and separated by binary leader.

The reason for this is that Rick Merrill decided to split the source code
up into FOCAL.ZZM and FLOAT.ZZM.  (His naming convention is to start at
.ZZZ and newer edits go backwards!)  Each can be assembled separately, and
there are only a few global equates from one to the other.  FLOAT is mostly
the floating point interpreter and input output routines while FOCAL is
the language interpreter, etc.

>through the above once in a blue moon.

This is only true for paper-tape users, which eventually were in the minority.
Most serious users of the -8 could run at least P?S/8 from a DECtape and
in fact ran OS/8 from a DECtape, RX01/02 or RK8E or other disk such as the
DSD-240 half-removable cartridge disk, etc.

cjl

---

From: [email-masked]
Date: Thu, 4 Nov 1993 16:33:18 GMT

>From article <[email-masked]>,
by [email-masked] (gordon hlavenka):
> 
> It seems to me that it was actually "A=10", "B=11", etc., similar to
> Hexadecimal notation.  Someday I'll put FOCAL,1969 back on my 8e and
> try it.

Having FOCAL 1969 handy, running on an emulator on my workstation, here's
the definitive answer, cut and pasted from the window where I ran it:

--- cut
CONGRATULATIONS!!
YOU HAVE SUCCESSFULLY LOADED 'FOCAL,1969' ON A PDP-8 COMPUTER.

SHALL I RETAIN LOG, EXP, ATN ?:YES

PROCEED.

*T 0A,0B,0C," ... ",0X,0Y,0Z,!
=    1.0000=    2.0000=    3.0000 ... =   24.0000=   25.0000=   26.0000
*T 0AA,0K,!
=   11.0000=   11.0000
*
--- cut

So, it wasn't like hex at all.  The second example above makes it clear
that FOCAL is of only limited use for text processing!

					Doug Jones
					[email-masked]

---

From: [email-masked] (Crystobal J. Junta)
Date: 3 Nov 93 12:57:15 GMT

In article <[email-masked]>, [email-masked] (Jon Krueger) writes:
|> Charles Lasner writes:
|> 
|> > Perhaps we need a definitive spec for just what FOCAL actually is.
|> 
|> I can see it now ... ANSI FOCAL :-)
And why not? :-)

---

From: [email-masked] (gordon hlavenka)
Date: Wed, 3 Nov 1993 21:06:18 GMT

Magnus Olsson <[email-masked]> wrote:
>
>Also, which is more important, the interesting "letters as digits"
>feature of FOCAL doesn't seem to work. I'm of course referring to the
>fact that all letters except 'E' should be interpreted as digits, so
>that 'A'=1, 'B'=2 and so on, and that it should be possible to use
>numerical literals such as "0YES" and "0NO".

-- 
----------------------------------------------------
Gordon S. Hlavenka           [email-masked]
Proud father of Daniel Scott     born August 9, 1993

---

From: [email-masked] (gordon hlavenka)
Date: 7 Nov 93 08:01:35 GMT

>*T 0A,0B,0C," ... ",0X,0Y,0Z,!

I stand corrected.

---

From: [email-masked]
Date: 11 Nov 93 09:44:28 +1030

> |> I can see it now ... ANSI FOCAL :-)

It shouldn't be hard to standardise - wasn't DEC the only implementor ?

Regards,

John Bennett                                   [email-masked]

---

From: [email-masked] (Charles Lasner)
Date: 13 Nov 1993 02:07:46 GMT

>It shouldn't be hard to standardise - wasn't DEC the only implementor ?

Well....

It depends on how you look at it:

    The original FOCAL is the product of the twisted mind of Richard
Merrill, or Rick Focal as some people refer to him :-).  He released
two different versions of it, the original usually known as FOCAL,
8/68, which is somewhat incompatible with later versions, and FOCAL,
1969 which is usually the definitive version.  All known variants do
stem from these two versions, but not necessarily compatibly.

    Some high-schoolers produced improvements and variants on the
8/68 version that eventually were known by names such as FOCAL '73
and TAFT FOCAL.  Still others produced variants on FOCAL, 1969 which
led to the versions for P?S/8 and OS/8. 
 
    The P?S/8 one tends to be as compatible as possible at the binary
level because there is also a large amount of documentation on how to
patch and customize the original 1969 version that would otherwise go
to waste.  The P?S/8 version is copyright me personally, and consists
of an assembly language overlay to the unmodified original.  Legally,
DEC owns the paper-tape binary that you load before my modifications
that turn it into the P?S/8 system program, so in theory, until DEC
releases FOCAL, 1969, you must independently come up with your own
copy of FOCAL, 1969 in binary form (presumably paper-tape which is
then read into P?S/8 as a binary file, etc.) to allow the creation of
the composite P?S/8 system program, etc.

    In general, the P?S/8 version is compatible with the original.
Several routines have been rewritten to save space, such as the
original SQRT function has been recoded in about 30% of the original
space with more accuracy!  Some of the P?S/8 modifications are to
implement option switches to produce some of the more popular
patches.  For example, some people have posted FOCAL output showing
the obnoxious "=" sign in the output.  While it is true that it's
cute to type up a program such as:

Type 1+1
=    2.00000*

The presence of the equals sign quickly gets tiresome.  When you
invoke the P?S/8 system program FOCAL with the /E switch set, you get
the equals (for compatibility!) but the default is to remove it.
(This allows FOCAL programming to format the output precisely.  Look
in the Programming Languages manual for some awful output examples
where the presence of the equals makes no esthetic sense, etc.)
There are other similar small patch option switches such as removing
the input prompt character which makes it useful for batch input
processing, etc.  Other P?S/8 enhancements have to do with
interfacing to the P?S/8 file system so that binary patch files and
FOCAL source and data files can be passed to FOCAL.  The assembly
language patches can be created exactly as described in the
prevailing documentation, and then assembled.  The resulting binary
files can overlay FOCAL directly, since the P?S/8 implementation also
includes a binary patch loader that's compatible with the normal
P?S/8 binary loader (except it cannot load areas of memory outside of
FOCAL's perview, etc.).  Thus, the entire thrust of P?S/8 FOCAL is to
be as compatible as possible with FOCAL, 1969, but add in the utility
of the O/S and avoid the drudgery of paper-tape, etc.

    There are various versions of derivatives of FOCAL, 1969 for
OS/8, the original having been known as OMSI FOCAL.  The final
variant of that derivative is generally known as FOCAL F.  (The
binary file may be called something like FOCL.SV, etc.)  (I believe
the author is Jim Van Zee.)  Many changes internally have been done
to this FOCAL, which now requires 8K.  (Note that the original and
the P?S/8 version both run in 4K;  there is an official 8K patch for
the 4K versions, and P?S/8 is compatible with the 8K patch as well.)
Access to the OS/8 file system is available, as well as many
additional built-in functions.  (Note: one of the most powerful
features of FOCAL is that you can roll your own function add-ons in
assembly language to do virtually anything.  The original and P?S/8
allow this intended function, but FOCL doesn't really have as much
capability in this area, as well as being fairly incompatible with
the original, and largely undocumented.  The original is so well
documented that there are even DECUS-supported documents on how to
patch and write your own add-on functions.  P?S/8 FOCAL is compatible
with virtually every aspect of the documentation, etc.)

    The source of FOCAL, 1969 was migrated to the PDP-9/15 using a
brute force approach: a common utility on the PDP-9/15 called 89TRAN.
(The program I believe was originally known as 8TRAN, but the later
version gives some control as to what aspects of the PDP-15 are/are
not taken advantage of.  PDP-9 code can run in page mode on the
PDP-15, but PDP-15 bank mode code cannot run on a PDP-9, etc.)  Thus,
the implemented language should be fairly close to the PDP-8
original.

    There exists a variant of FOCAL expressly for the PDP-12 and the
DIAL-MS operating system called FOCAL-12.  It was developed by Lenny
Elekman using the DIAL10 (aka PAL12) bi-lingual variant of the PAL10
PDP-10 TOPS10 PDP-8 cross-assembler.  (Note: the source of FOCAL-12
is not assemblable on the PDP-12!  This is because the DIAL-MS
assembler is not compatible enough with PAL12!  The later OS/8
product aka PAL12 is somewhat closer to being compatible and can
assemble the source with a few changes, but the
only known PDP-8 method to assemble the original source without
modifications is to use the P?S/8 PAL assembler with the bi-lingual
option switch set.  In that mode, the P?S/8 assembler not only
assembles normal PDP-8 code using two's complement arithmetic where
necessary, it also becomes a LINC assembler for 10-bit segment
addressing and one's complement arithmetic.  FOCAL-12 is written
largely in LINC mode to accomodate the PDP-12 hardware, etc.)

    The binary output obtained by assembling FOCAL-12 must be loaded
into DIAL-MS where it runs as a normal user binary program.  Once
loaded, Library commands can be used to access DIAL-MS files.  (Note:
P?S/8 supports certain display overlay packages that are somewhat
compatible with the related syntax of FOCAL-12, i.e., the analogous
functions of FOCAL-12 were used as a model for the display function
patches for P?S/8 FOCAL, thus in part, FOCAL-12 documentation also
explains the P?S/8 version when used that way, etc.)

    The starting point for FOCAL-12 was FOCAL, 1969, so, putting
aside the PDP-12 and DIAL-MS specific augmentations, the language is
pretty much the same.  FOCAL-12 also corrects a minor bug in the
"ASK" command of FOCAL, 1969.

    A dubious project later at DEC produced FOCAL-8.  FOCAL-8, in
spite of what might be thought about it, consists merely of FOCAL,
1969 with the following changes/additions:

1)  A reprinted manual, using the then current new cover style.

2)  Patches to the portions of FOCAL concerned with configuring it
    for various computers.

3)  The afore-mentioned fix to the "ASK" command code taken from
    FOCAL-12.

(Of the three areas, #1 is clearly the most useful :-).  Note: the
equivalent of the FOCAL-12 derived fix is contained in the P?S/8
FOCAL implementation.  Basically, the problem involves making the
code one word longer, thus making FOCAL-8 not as binary-compatible
with FOCAL, 1969 as could be achieved.  (The affected page becomes
mostly an address off, etc.)  However, by cleverly recoding another
routine on the same page, said routine becomes one word shorter.
Thus, the net effect of introducing the optimization and bug fix is
to occupy the same amount of space.  The entire sequence is about
20-odd words long to implement the fix to the binary of FOCAL, 1969
and is now standard in P?S/8 FOCAL.  Thus, it wasn't necessary to
make the binary of FOCAL-8 incompatible with FOCAL, 1969, yet this is
what was done!)

    The model-dependent patches are a curiousity in themselves:  The
original FOCAL, 1969 can run on a PDP-5 by discovering that the CPU
was a -5 and self-patching the interrupt handler, etc.  It can also
run on an 8/s by avoiding the instructions only available in later
models.  Since FOCAL, 1969 was introduced before the 8/e, only prior
models are identified, although it runs fine on any 8/e,f,m,a system
except for mis-identifying the machine as a PDP-8.  All other models
of PDP-8 are specifically called out: PDP-8, 8/i, 8/l, LINC-8, -12,
and a special-case where the machine has an AX08 attached to it
changes the name to LAB-8, and makes some of the built-in functions
work for the AX08.  However, FOCAL-8 only runs on 8/e or newer!
Most, but not all of the model-checking is excised out, but not in a
straight-forward way, since there is also a hidden agenda or two:

a)  DEC actually sold a patch to FOCAL-8 known as the "FOCAL-8 Family
of -8" patch.  What this did was merely to restore the original
capability of FOCAL, 1969!  (Note: FOCAL, 1969 was distributed free
to -8 purchasers, but the FOCAL-8 patch cost extra to accomplish the
same thing!)

b)  In an incredibly sneaky manner, the model-check code in FOCAL-8
includes an unorthodox check for the DCC-112 series of computers,
sold by Digital Computer Controls (later a division of Data General).
These computers were serious competition to the PDP-8 and actually
in some cases run faster than the 8/e (but have positive bus, not
Omnibus).  The way the sneaky code works is it references two
instructions by adding them together, then adding on a fudge-factor
constant to the sum, produces an OPR-class instruction which is then
stored in-line and executed.  Depending on the results of the way the
AC changes, the code decides whether or not the CPU is allegedly one
of the DCC models.  If not, the code proceeds normally to startup the
rest of FOCAL in the normal manner.  However, if the CPU is
discovered to be a DCC machine, certain important pointers are
clobbered so that as programs are loaded later, FOCAL will tend to
self-destruct!  The effect is cumulative, so that minor testing will
seem to work, yet significent program loading will tend to shred the
code as the stack pointer points to code instead of free space!
Since the OPR instruction that starts this operation isn't in the
binary, and the temporary location where it's executed is overlayed
long before the rest of FOCAL is operational, it's virtually
impossible to find this nasty test.  (This may be the earliest
documented "computer virus"!)  Additionally, the listing file sold by
DEC for FOCAL-8 uses XLIST in the area of the sneaky code, so the
listing is deliberately obscuring only this small portion of the
code.  The listing is cleverly showing a dodge: some seemingly
innocent code is generated where the sneaky code goes, however,
examination of the binary shows the origin setting backs up and there
is double-loading in the affected areas.  The binary in memory is as
I described it, not as the listing indicates! (The listing shows the
first binary load, but the sneaky code is the second binary load,
thus overlaying the first code.  Using BITMAP of P?S/8 or OS/8
plainly shows double-loading in the affected area when you read in
the paper-tape of FOCAL-8, etc.) (Somewhere, I have a source file I
wrote up, which plainly shows all of the binary differences between
FOCAL-8 and FOCAL, 1969, which are otherwise minimal.  You assemble
the short file, and then load FOCAL, 1969 followed by the binary
derived from this source file, and the result is the FOCAL-8 binary,
including the sneaky patch.  My original intent in producing the file
was to help eliminate that "ASK" code bug, but the file also shows
someone's less than honorable intentions, etc. in writing the
model-testing code; there is no useful purpose served in making FOCAL
self-destruct!)

    I will leave it to others to describe the FOCAL-11 variations,
which I understand are quite substantial.  (But could merely be
function differences, not language differences!)

cjl

---

From: [email-masked] (Stephen Quigg)
Date: Sun, 14 Nov 1993 21:41:41 GMT

Here's a "real" FOCAL program. It comes from volume 2 of "Programming 
Languages" (1970). I typed it in by hand, so there may still be a typo in it,
but what I've given you is a session run on my '8/E, ie the program DOES run.
For those of you running FOCAL on an '8, Load FOCAL-8 without extended 
functions, then load "King of Sumeria". I did this using a comms program 
called PROCOMM; I simply did an ASCII transfer after setting up a delay after
each line sent to allow FOCAL time to digest it. The session that follows
was captured under the "log" feature of PROCOMM.
  I have some other FOCAL games etc on paper tape. Now that I have the means
to get stuff out to the "real" world, I'll try to post some more soon.

Cheers,
Steve Quigg.

PS There's a few PDP-8 enthusiasts here in OZ, but the alt.sys.pdp8 newsgroup
doesn't seem to get in or out of the country; all we get is stuff that was
cross-posted, that seems to then filter back into alt.sys.pdp8 once it gets
here.

------------------------------------------------------------------------------
King of Sumaria
ABSTRACT: The "King of Sumaria" is a game which challenges your ability to
forsee the consumer market. Hamurabi, your servant, will state the following
facts about last year, and you must decide the number of acres you will need,
and how many bushels of grain you expect to distribute as food. You will base
your decisions on these facts.
  1. Number of people who died of starvation.
  2. Number of new people who came to the city.
  3. Number of acres owned by the city.
  4. Number of bushels harvested per acre.
  5. Total number of bushels that were harvested.
  6. Number of bushels that were destroyed.
  7. Number of bushels currently in storage.
  Then, based on your decisions, Hamurabi will state a new report of the 
above information.

WRITE ALL
C-FOCAL,1969

01.10 S P=95;S S=2800;S H=3000;S E= 200;S Y=3;S A=1000;S I=5;S Q=1

02.10 S D=0
02.20 D 6;T !!!"LAST YEAR"!D," STARVED,
02.25 T !I," ARRIVED,";S P=P+I;I (-Q)2.3
02.27 S P=FITR(P/2);T !"**PLAGUE**"!
02.30 T !"POPULATION IS"P,!!"THE CITY OWNS
02.35 T A," ACRES."!!;I (H-1)2.5;T "WE HARVESTED
02.40 D 3.2
02.50 T !" RATS ATE "E," BUSHELS, YOU NOW HAVE
02.60 T !S," BUSHELS IN STORE."!

03.10 D 6; D 8;S Y=C+17;T "LAND IS TRADING AT
03.20 T Y," BUSHELS PER ACRE;";S C=1
03.30 D 4.3;A " BUY?"!Q;I (Q)7.2,3.8
03.40 I (Y*Q-S)3.9,3.6;D 4.6;G 3.3
03.50 D 4.5;G 3.3
03.60 D 3.9:G 4.8
03.70 S A=A+Q;S S=Y*Q;S C=0
03.80 A !"TO SELL?"!Q;I (Q)7.2,3.9;S Q=-Q;I (A+Q)3.5
03.90 S A=A+Q;S S=S-Y*Q;S C=0

04.10 T !"BUSHELS TO USE
04.11 A " AS FOOD?"!Q;I (Q)7.7;I (Q-S)4.2,4.7;D 4.6;G 4.1
04.20 S S=S-Q;S C=1
04.30 A !"HOW MANY ACRES OF LAND DO YOU WISH TO
04.35 A !"PLANT WITH SEED? "D
04.40 I (D)7.2;I (A-D)4.45;I (FITR(D/2)-S-1)4.65;D 4.6;G 4.3
04.45 D 4.5;G 4.3
04.50 D 7;T A," ACRES."!
04.60 D 7;D 2.6
04.65 I (D-10*P-1)5.1;D 7;T P," PEOPLE."!;G 4.3
04.70 D 4.2
04.80 D 6;T "YOU HAVE NO GRAIN LEFT AS SEED !!"!S D=0

05.10 S S=S-FITR(D/2);D 8;S Y=C;S H=D*Y
05.20 D 8;S E=0;I (FITR(C/2)-C/2)5.3;S E=S/C
05.30 S S=S-E+H;D 8;S I=FITR(C*(20*A+S)/P/100+1);S C=FITR(Q/20)
05.40 S Q=FITR(10*FABS(FRAN()));I (P-C)2.1;S D=P-C;S P=C;G 2.2

06.10 T !!"HAMURABI:  "%5

07.10 I (C)7.2;S C=C-1;D 6;T "BUT YOU HAVE ONLY";R
07.20 D 6;T !"GOODBYE!"!!;Q

08.10 S C=FITR(5*ABS(FRAN()))+1
*
*
*GO

HAMURABI:  

LAST YEAR
=     0 STARVED,
=     5 ARRIVED,
POPULATION IS=   100

THE CITY OWNS=  1000 ACRES.

WE HARVESTED=     3 BUSHELS PER ACRE;
 RATS ATE =   200 BUSHELS, YOU NOW HAVE
=  2800 BUSHELS IN STORE.

HAMURABI:  LAND IS TRADING AT=    18 BUSHELS PER ACRE;
HOW MANY ACRES OF LAND DO YOU WISH TO BUY?
:0

TO SELL?
:0

BUSHELS TO USE AS FOOD?
:2000

HOW MANY ACRES OF LAND DO YOU WISH TO
PLANT WITH SEED? :800

HAMURABI:  

LAST YEAR
=     0 STARVED,
=     3 ARRIVED,
POPULATION IS=   103

THE CITY OWNS=  1000 ACRES.

WE HARVESTED=     1 BUSHELS PER ACRE;
 RATS ATE =     0 BUSHELS, YOU NOW HAVE
=  1200 BUSHELS IN STORE.

HAMURABI:  LAND IS TRADING AT=    18 BUSHELS PER ACRE;
HOW MANY ACRES OF LAND DO YOU WISH TO BUY?
:?01.00 @ 03.30 
*