The figForth Paradigm

Note:
There is extensive use of “Tooltips” text to support learning which do not seem to render on a Smartphone
Therefore this site is best viewed via a computer’s HD monitor


Previous Section: The Forth Paradigm

Paradigm: “a model of something, or a very clear and typical example of something” Cambridge Dictionary

1. What is figForth?

The “Classic figForth Model”

What is described in this section is the Classic figForth Model which is now rather outdated 1

What originally popularised Forth during the late 1970’s was when FIG (the Forth Interest Group) in the US released assembler source listings 2 (known as “models”) for a number of popular microprocessors of the time (6800, 6502, 8080, etc). These would be entered up in the host computer, then assembled and would lead to an executable Forth on your chosen machine/microprocessor

Even though these microprocessors are 8-bit machines, figForth is a 16-bit system which works in any number base

figForth model input and output was via serial ports so it was very easy to get a Forth implementation up-an-running for a target with at least one RS-232 serial port. No operating system required!

1.1 figForth is WRITTEN IN ITSELF !!

Forth is reflective, i.e. it’s written in Forth itself with a small number of machine code primitives called “Code Definitions” so that it could be run on any real microprocessor

Detailed discussion…

figForth is comprised of and compiles to Indirectly Threaded Code, and so its internal form is a list of code-field addresses (“CFA”s) with a simple text header forming part of a linked-list for interpretive use. 3 This was the format of the figForth models compatible with the assemblers of the time. In order to execute any of the indirectly threaded definitions, Forth contains a simple virtual machine

2. The Essence of figForth

At the time fig was active, many of the home computer systems available were very rudamentary - having very little memory, a “machine code monitor” and very slow cassette tape storage 4

The machine code monitor offered an “application programming interface (API)”. This allowed user programs access to the internal routines of the home computer, such as “write an ASCII character to the screen”, etc

figForth needed to use only three API (system) calls:

  • Wait for a character from the Keyboard
  • Has a key on the keyboard been pressed?
  • Display a character on the screen

It implemented a simple “virtual memory” block scheme to allow source editing and saving and loading that source via the cassette tape interface

The requirements above determined the structure and implementation of figForth

The whole figForth compiled code is less than 8k bytes in size, and can run in less than 2k bytes of RAM, although 8k of RAM is preferred

3. What figForth is MISSING OUT

Nothing is “Event-Driven” and so “polling” must be used
To include anything interrupt-driven would have made figForth very machine-dependent

David Husband’s eZ80 figForth (which he uses for his own internal purposes) supports low-level machine-code interrupts directly and high-level interrupts (Tasks) via a simple multi-tasking mechanism…

Discussion here

4. The figForth Software Model

Due to the great work of the original fig 5 pioneers, figForth is well-structured, well-specified and its architecture is “neat” and largely processor-independent

4.1 figForth’s Internals

4.2 Why are the internals of interest?

  1. The fundamentally different nature of a Forth Application where the language itself is extended to encompass the desired solution rather than as in a C application where the desired solution is “merely” expressed in terms of the existing and un-modified C language

  2. Advanced Forth programming involving embedded hardware & software, such as I am doing here, involves & requires an expert knowledge and appreciation of the Forth internals

  3. Forth is not a mainstream language and most books on the subject are long out-of-print or very obscure, and so therefore are not easily accessible; so this is to assist the reader in gaining an understanding and appreciation of the what’s, why’s and how’s of the main ideas and methods used on this website

Forth is extremely powerful and internally very neat. I have learned from my own experience that having a deeper understanding of how and why Forth does things is essential to the understanding and effective use of the Forth language (Ting 2013, p. iii)

I have very rarely had to design anything completely from scratch, usually I can use or modify some existing Forth word; and this is what I have done many times in the past… Why re-invent the wheel?

A detailed discussion of figForth’s Internals

5. The Classic, Outdated figForth Hardware Model

This was the relatively very simple figForth model promoted very successfully in the early 1980’s by the Forth Interest Group (“FIG”), and although it is still a valid system, it has very limited uses nowadays and would be completely useless to implement any Internet of Things devices…6

In the case of the early figForth systems, the host was a very rudamentary home computer but later “embedded systems” without a keyboard or screen started to emerge and the early classic figForth hardware model changed to a system with a serial port, but the original figForth implemention/installation requirements still held true

Image#1 - A Typical “Classic” Embedded Forth System (Now outdated) - Image: (Husband 2011)

6. The New figForth Hardware Model

I am sure we are all familiar with how most embedded systems work nowadays with their user-interface operations being based upon talking to them via an Internet browser program and their support for various USB devices…

So, “talking to them via an Internet browser program” all sounds so simple and straight-forward, but is technically quite complex… Your embedded system needs to run as its own website, serving or “pushing” dynamic web pages over an Ethernet interface via the HTTP & TCP/IP protocol 7

Image#2 - A “New Model” Embedded Forth System - Image: (Husband 2020)

(1) - The Ethernet Interface

Most will now be familiar with an embedded device/product such as an ethernet hub or adsl/wi-fi hub/modem that you use an Web Browser to communicate with over the ethernet interface. What this actually means is that the device is having to run its own web server. This is quite complex to implement !!

More on the Ethernet Interface…

(2) - The RS-232 Interface

The RS-232 is a very widespread kind of serial port

More on the RS-232 port…

(3) - The USB Interface

USB, by its very nature is quite complex and at an early stage, design decisions 8 must be made. The MAX3421 USB Peripheral/Host Controller which interfaces to an SPI interface is my favourite, but for a product development platform, you’d want two USB interfaces using the MAX3421 controller, because you might well want/need to implement a Host USB and a Peripheral USB

More on the USB port…

(4) - The SPI Interface

The Serial Peripheral Interface (“SPI”) is a synchronous serial communication interface specification used for short-distance communication, primarily in embedded systems. The interface was developed by Motorola in the mid-1980s and has become a de facto standard. Typical applications include Secure Digital cards and liquid crystal displays”

Note: In Image#2 above, the USB devices discussed in (3) are driven by the SPI Bus shown at (4)

More on the SPI bus…

More on Interfacing to Hardware…

7. figForth Refuses to Die!

Strange, but very true

Important Note

From here onwards, when we refer to Forth, we mean figForth !!

Next Section: Inside figForth

References:

Husband, D., 2011. M.Sc in IT (Software Engineering). Master’s thesis. University of Liverpool.

Husband, D., 2020. The New Forth Hardware Model. Baremetal Engineer Extraordinaire [online]. Available from: Http://baremetal.engineer/baremetal.software.engineer.pdf.

Ting, C. H., 2013. Systems Guide to fig-Forth [online]. 3rd ed. San Mateo, CA 94402, USA: Offete Enterprises, Inc. Available from: http://figforth.org.uk/library/Systems.Guide.to.figForth.pdf.

  1. But still perfectly viable and usable as an “early development” system to get a basic forth “up-and-running”… 

  2. And the listings were originally just paper printouts, so you had to type in 100+ pages into your text editor to just get started. That was the 1st test of dedication…! 

  3. This is the “Dictionary” which is about 90% of Forth… 

  4. And in those days there were virtually no “embedded systems” available to the public 

  5. “FIG” - The worldwide Forth Interest Group has been defunct for many years… UK FIG: http://www.figuk.plus.com/ 

  6. Because it has no USB or Network Connectivity, either Ethernet or Wi-Fi 

  7. However, that would still be very difficult to develop, test and debug without running a terminal program on the RS-232 serial port !! 

  8. For instance, is my USB interface going to be a peripheral or a host? Do I need both? 


Updated: 3rd September 2022 by David Husband
© 2021 David Husband, a.k.a. Baremetal Engineer Extraordinaire
All Rights Reserved – All Trademarks & Copyrights Acknowledged
All personal information is subject to the Data Protection Act 2018 & the UK GDPR
“ad auxilium aliis ad auxilium sibi”