Saturday, March 17, 2018

Historical recreation/restoration of original FORTH on the IBM 1130

TESTING OUT ORIGINAL FORTH IMPLEMENTATION (FOR IBM 1130)

FORTH was created back in 1968 on an IBM 1130 by Charles Moore, then ported to a large number of machines and expanded over the years. I managed to get the scanned listing pages of his original code working on the IBM 1130 simulator from Brian Knittel.

The system consisted of a 12 page assembler program that scanned input from disk, parsed it into words and processed a dictionary. It implemented a small number of primitive operations itself, but opened and processed a disk file with more than 200 punched card images to extend the language to its full breadth. 

The disk file teaches the system how to compile FORTH statements into 1130 machine code, adds a wealth of verbs, provides console/keyboard support and implements a disk based file access. The culmination of this 'boot up' disk file is a prompt on the console printer (HI THERE) and the ability to type in FORTH statements interactively.

The language evolved quite a bit from this first implementation, thus part of the restoration of the system involves reverse engineering, with the aid of 'archeological study' using old documents written by Moore and others from 1970 and later. 

The modern FORTH language defines words (verbs) using a colon (:) to begin and terminates the definition by a semicolon (;). Chuck Moore allowed for and used synonyms of period (.) and comma (,). In modern FORTH, the period is used to print the contents of the top of stack, but not in the original system.

The 200+ card images on the disk file used to 'boot up' FORTH are mostly sequences of definitions such as

.CREATE 2E0 SECTOR IN 1+ DUP INC 1- 7*+ S= SV VALUE 1+ SV 5+=
    RAISE SV 6+= RAISE F+ SV 7+= SV ALPHA 4 MOVE WRITE,

The above definition builds on many prior definitions - only the word INC is provided in the assembler program primitives while the rest are built up by prior card images. This establish an area on disk for FORTH statements to be stored and read, at a hard coded sector /02E0 on disk, thus working outside the 1130's monitor system and utilities. 

In addition to definitions, FORTH will compile verbs to 1130 machine instructions using the keyword OPERATION, but that keyword is not used in modern FORTH. These compiled definitions look like 

OPERATION CHARACTER RESTORE 0A00 A 1+ GXIO A 1+ LOAD
   ST X1 DEPOSIT LOC CONVERT CALL CSCP LD REL CHA CONTINUE

This verb CHARACTER above will compile an 1130 instruction to directly do I/O to the keyboard, yielding an XIO instruction which reads one keystroke. It then calls a compiled routine to convert the input character from hollerith card code, converts it over to the console printer coding (selectric PTTC/8) and does an echo of the key to the printer. 

By the time of the CHARACTER definition, substantial functionality is already present, culminating in the final card image (FORTH statement) that starts the interactive user session:

LOC DONE 0A= HOME 'HI THERE' REPLY CONSOLE

The verb HOME, for example, will cause the disk drive to seek to track 0 (its home position), types HI THERE on the console printer and waits for user commands from the console. 

Since FORTH bypasses the 1130 monitor system and utilities, it takes direct control of the disk for its boot up file and user files. The assembler program has hardcoded the location on disk of the 200+ boot up card images. The FORTH statements in the boot up disk file have hardcoded locations such as sector /2E0 which is track 92, head 0, sector 0 on the disk. 

In order to get this running, I had to coerce the 1130 monitor and utilities in order to store the boot up card images on disk and to allow writing to sector /2E0 where FORTH is pointing. The monitor protects stored programs and data by setting a file protect line, below which writes are blocked, so I needed a disk image where the file protect line was below track 92. 

An 1130 can have disk packs mounted in a number of different disk drives. The monitor uses cartridge serial numbers to name packs, allowing files to be located by cartridge number and file name. FORTH does away with this. The verb HOME was coded to talk to the second disk drive, thus I had to discover this and establish a disk image mounted on that drive to allow FORTH to run.

At this point, I can issue FORTH commands and interact, but I don't understand some critical facts yet. These would have been documented in a language reference or with comments in a more modern version of FORTH, but this first instance was purely used by Charles Moore. It had no other users and no need for such documentation.

Before the second programmer began to use FORTH, it had been ported to a Burroughs machine with some significant change to the language, then evolved further as Charles Moore moved to new employment and eventually founded the FORTH company to spread the language. 

I have two documents written by Moore while he was at the original site of FORTH (Mohasco Inc) but written in 1970 after he had already evolved it to the Burroughs versions with features such as multi-user operation that didn't exist on the 1130. Neither of these is a language reference, but they do reflect the concepts and principles upon which FORTH was built. 

Somewhat later documents, such as a history of the early years of FORTH written by Moore or a user guide from Kitts Peak Observatory written in 1979, offer hazier hints. Some command verbs had changed two or more times between the 1968 FORTH and the versions discussed in these later documents.

Bob Flanders and I will be painstakingly studying the dense and undocumented FORTH boot up card images alongside the Rosetta Stone documents listed above, hoping to build up enough of an understanding, an informal language reference for original 1968 FORTH, that we use it for programming purposes. 

13 comments:

  1. God sayeth "Go forth and multiply" but the programmers cried "Oh Lord, we cannot do floating point arithmetic with FORTH!" And so, FORTH went forth with newer versions.

    ReplyDelete
  2. Lovely! I had no idea Forth originated in an 1130! I thought it started on a microprocessor.

    ReplyDelete
  3. Per Wikipedia, Charles H. "Chuck" Moore is still alive (b. 1938). Any thought of trying to get in touch with him?

    ReplyDelete
  4. The 1130 history is covered in Section 1.1 (Early Development) in The Evolution of Forth. The full text can be found here: https://www.forth.com/resources/forth-programming-language/

    ReplyDelete
  5. We have exchanged emails with him - he was not aware of any copies but as I wrote, an old email from Chuck did contain scans. At the time, Chuck said he didn't know what the four pages were - that turned out to be FORTH - which is due to the drift in the language since the very early days.

    . and , in the four pages were synonyms for : and ; which FORTH programmers would have recognized. OPERATION in the four pages was replaced after the initial days by CODE. Plus, the first part is mainly definitions of the IBM 1130 machine instructions that would be needed to compile FORTH statements during execution, but are obscure looking hex constants.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This is absolutely awesome.

    I can't wait to try this out for myself, regardless of how buggy it is.

    Would it be possible to get in touch with Chuck and get his go-ahead on releasing this original code?

    I'm curious what was in the original set of 16 scans, and whether that info would be interesting as well.

    - David Lindsay

    ReplyDelete
  9. Great to hear about the restoration! I started Forth programming in the early 90s and I've recently come back to it for fun. Learning about it's history is very interesting to me.

    ReplyDelete
  10. David - Chuck was releasing the original code to Bob Flanders for sharing with the 1130 enthusiasts back when he emailed the scanned images in 2011. He also knows we found it and are recovering it.

    We will share the machine readable version soon, in a setup for use with the 1130 simulator from www.ibm1130.org and have already shared the 16 original scans with SV-FIG

    ReplyDelete
  11. I was an IBM 1130 programmer (assembler and FORTRAN) for a while (1966 - 1967, but I don't remember how many months). I don't remember much about it but it was a pretty simple operation set. I learned FORTH on the Commodore 64.

    How much of this is working now? Is there a package that will work with simh?

    ReplyDelete
    Replies
    1. There is a great simulator package with software at http://ibm1130.org/ which will allow you to have your own virtual 1130, operate and program it.

      Delete