In the ’80s, Beginner’s All-purpose Symbolic Instruction Code (BASIC) was the predominant programming language for home computers. Of course, it was not the BASIC that Kemeny and Kurtz wanted – although Kurtz seemed to be less anal about it than Kemeny –, it was the entry point into computer science for many bedroom programmers. In other words, 99% of the computers you could buy were talking a dialect of BASIC as soon as they were switched on. The other option you always had was the much less palatable machine language. Now, you may ask yourself about that missing 1%, right? Well, with some obscure machines, you could do FORTH natively! For example, with the British Jupiter ACE by Cantab or the much more capable French Hector HRX by Hector. For those of you who don’t know FORTH, it was invented by Charles Moore in the late ’60s to drive a radio telescope. By itself, this fact is not very interesting, except that it gives us some clues on his design choices for this really nice language: FORTH is small, frugal in memory, almost as fast as machine language in its worst implementations, interactive, and … cool. To be fair, FORTH’s detractors call it a write once read never (WORN) language.
At the end of the day, it is a question of taste I presume. I do love FORTH, as well as the concept of stack machine it is built upon. The same way I like to describe the C language as a universal assembler, FORTH is the definitive interactive assembler to me. If you have not heard of FORTH, it is likely because you are not working/interested in the fields where FORTH is well established: aerospace, machine control, firmware development, etc. Interested? If so, I will show you how you can evaluate this language with a low-cost micro-controller and an In-System Programmer (ISP). In particular, I am using an Arduino Uno and a WaveShare USB AVRISP XPII ISP (but you can pick any Atmel AVR compatible ISP). You will then need to download a free evaluation version of the SwitX Cross Compilers for Micro-controllers from https://www.forth.com/download/. FYI, the license cost for the AVR Lite version is $295. But for an evaluation, it will cost you nothing! Note that the evaluation time is not limited, but the target object code size is. SwiftX is sold by FORTH Inc., the company co-founded by Chuck Moore and Elizabeth Rather in the early ’70s, almost 50 years ago. Once the package installed on your PC, you have all you need to build, upload and run the SOS demo application. The operations can be described as follows: connect the ISP to the Uno’s ICSP connector and connect both (the Uno and the ISP) to your computer. Both should show-up in your devices manager if all the drivers are correctly installed. Open the SwiftX IDE – this is done by opening a project (the SOS one for example) and not the executable. You then have to build a FORTH kernel (an IDE menu option). This generates a target.hex file (~90KB). Push the kernel to the Uno by typing RELOAD!. Behind the scene, the AVRDUDE EEPROM/flash programmer, which is included in the package, is used by the IDE. At this point, the SOS sample is running (see attached video). While the code is running in the background, you can connect to the Uno in debug mode from the IDE, and execute any FORTH code/command! Indeed, SwiftX is multitasking (yes, in less than 100KB). The commands are sent via the ISP to the Uno, executed by the FORTH kernel, and the stack (or result) is sent back to the IDE. Et voila! If you are a retro-computing aficionado, you can take a pause, and contemplate the fact that you have just set up a system that is almost 5000 times faster and has 30 times more memory than the Jupiter Ace! To start exploring FORTH, you can read the Forth Programmer’s Handbook copy shipped with SwiftX. As a next step, one can refer to the ANSI X3.215-1994 language reference (also provided). When you will start interacting with FORTH, you can display the stack in a non-destructive way using .S command as usual, but the IDE also displays the stack in the window’s status bar! Last but not least: type WORDS to have the content of the dictionary (equivalent to the list of all the FORTH instructions, plus the ones you have defined). Now it is up to you, and may the FORTH be with you!
8 thoughts on “Swift as FORTH!”
Excellent post Jamel – thank you! So the whole device chain is USB-powered off of your computer?
r cs thank you! Yes, all power is provided by the PC’s USB ports. Now if the Uno had to power devices itself, it would require external power supply.
Do you think an UNO could be crafted into an external FORTH computer you could plug into something with USB or RS-232? Something like that could breathe life into all sorts of retro stuff if the external coprocessor was portable and accessible from lots of things.
r cs to respond your question: sure! You could even make it portable, battery powered and rechargeable when connected to a USB port. You may want to use a different FORTH option than the SwiftX, but that is a detail. What I am not sure to understand right is the use model you are describing in the comment. But for sure you can make a small FORTH system with all the options available on the market today. Hope I answered your question.
Jamel Tayeb Thanks for the posting. It would be fun to use Forth on some of my amateur astronomy projects and bring Forth full-circle, back to its roots. 🙂 Too bad it costs $$ to get serious.
The posting brings back old memories. I am old enough to actually have taken the Forth class from Charles Moore at the Forth, Inc. offices. Back in the early 80’s I used it on an Intel 8086 (8MHz) to implement a multichannel earthquake recording system. It was nice to develop a system in which I could fully understand and control everything in the system.
Dave Kodama thank you sharing your memories and cool experience with FORTH! Indeed it would be a nice loop to do an amateur astronomy project with this great system. Maybe there is already one out there. And I am with you, being able to understand and control the internals of a computer system is very gratifying.
Jamel Tayeb A couple more Forth tidbits:
– At the Forth, Inc. class, I think something like 10 of us in the class were time-sharing a low-end PDP-11 running entirely in Forth. There was no user/user/OS isolation so anyone who wrote a tight loop could lock up the system, but it was amazing that we could all work on our Forth exercises simultaneously on a low-end computer.
– Forth was used in the boot ROM of Sparc workstations— or at least it was in the Taiwanese clone of the Sparc I had.
– There was a version of Forth for the original (boxy) Macintosh (the Motorola 68000 one). I used it to implement a GUI control interface for a satellite communication emulator (used to test satellite ground stations).
You might be interested in Jeelabs’ JeeNode Zero, a small wireless-capable board with Forth firmware. And also the Forth sub-forum at forum.6502.org – • View forum – Forth