User Tools

Site Tools


mbstring extension must be loaded in order to run mPDF
sd:star_forth

Star Forth

Starting Forth is available online at Starting Forth Online Edition.

Welcome to Star Forth

SD/FORTH v0.5.1

  • 32-bit cells, subroutine-threaded
  • Outer interpreter with TIB, word parser, dictionary search, number parsing
  • Stack primitives with underflow protection
  • 19 built-in words: BYE, .S, CR, ., DUP, DROP, SWAP, OVER, +, -, *, /, MOD, EMIT, DEPTH, WORDS, PROMPT, HEX and DECIMAL
  • Decimal, hex ($), binary (%), explicit decimal (#) number input
  • Negative numbers with - prefix
  • Paste-friendly '> ' stripping

TODO:

  • : and ; (colon definitions) — this is where FORTH becomes a real language
  • 32-bit number printing (currently . only shows low 16 bits)
  • Control flow — IF/THEN/ELSE, DO/LOOP, BEGIN/UNTIL
  • Memory words — @, !, C@, C!, HERE, ALLOT, ,
  • String I/O — .“, TYPE, ACCEPT
  • Save/load dictionary images

FIG-FORTH

Here is the complete 8086 Assembly source code, commented, for fig-FORTH.

The forth interest group created various implementations, all listed here:

This list includes implementations for: the 1802, 6502, 6800, 68000, 6809, 8088, 9900, the Alpha Micro, Apple II, Eclipse, IBM-PC, Nova, Pace, the PDP-11, and the VAX.

The point being proven, FORTH is out there with copious amounts of code in various architectures. It was thus easy to get a kind of FORTH running on the SD-8516. I quickly became obsessed with it. It took quite a while to iron out all the stack bugs.

Why

Forth is one of the most fascinating and misunderstood languages ever created. Invented by Charles “Chuck” Moore around 1970 (originally for controlling radio telescopes at Kitt Peak National Radio Astronomy Observatory), it’s a stack-oriented, concatenative, postfix language that feels like a mix of assembly, a REPL, a compiler, an operating system, and a philosophy all in one.

Everything in Forth is a “word” (a subroutine). You define new words that build on old ones, and the language is extremely extensible; you can even change how the compiler works from inside the language itself. It runs in a tiny footprint (many classic implementations fit in 8 to 16 KB total) and gives you immediate, interactive feedback.

Forth vs. BASIC

Both are early 80s microcomputer languages – more or less. Both let you type something and see results instantly. But BASIC is an interpreter while Forth uses threaded code to compile programs on-the-fly.

To put it bluntly, Forth destroys classic interpreted BASIC on the same machine. On 8-bit computers (Commodore 64, Apple II, etc.) Forth was legendary. Often 10x to 20x faster than BASIC for the same tasks. Real benchmarks from the era and modern recreations show Forth loops, math, and hardware control running at near-assembly speeds.

Compared to C:

In embedded/microcontroller work, well-written Forth is usually within 10 to 30% of optimized C – and sometimes faster, because there’s no function-call overhead or hidden runtime.

What's more, FORTH binaries are dramatically smaller; a 10k FORTH binary will often have an equivalent C program binary of about 100k.

That being said, both Basic and C follow a somewhat straightforward English-style grammar while Forth uses RPN (because, of course, it is a stack machine). While not impossible to learn, some people just don't like it.

So! Forth has a steep initial learning curve; you must keep the stack in your head; but once past that it is astonishingly simple. The entire language core can be implemented in a few hundred lines of assembly. There are no complex syntax rules, no precedence battles, no huge standard library to learn.

Chuck Moore’s philosophy was radical minimalism: “If the program is too big, you’re doing it wrong.” This aligns with the UNIX philosophy neatly; “Small is beautiful.” Most serious Forth programs stay tiny by modern standards because the language forces you to rethink the problem until the solution shrinks.

Historical use compared to C

You can often use Forth to write more serious or useful applications than in a language like BASIC. FORTH has a different structure to BASIC – and even to C.

Forth was used for:

  • Real-time telescope control systems (1970s–80s)
  • Image processing at NASA Goddard and Naval labs
  • The entire Open Firmware boot system (used in Sun workstations, PowerPC Macs, and many servers)
  • Spacecraft: NASA’s Voyager probes, Space Shuttle Star Tracker, Philae lander on Rosetta, Galileo magnetometer, and derivatives of Moore’s RTX2000 chip still fly on NASA missions
  • Industrial control (factories, Owens-Corning distributed controllers)
  • Embedded microcontrollers today (Mecrisp, FlashForth, etc.) for sensors, robotics, and IoT

You can write “large” applications in Forth – people have built full operating systems, compilers, and CAD tools, but the culture strongly prefers composing many tiny words instead of monolithic code. Still, large Forth programs are usually smaller and more maintainable than equivalent C because of the extreme factoring.

Forth as a Serious Programming Language

Forth is not a toy language. Companies and agencies paid real money for it in the 1970s, 80s and 90s because it delivered real-time performance in a small memory footprint.

It’s still actively used in niches where C is too heavy or too slow to develop: radiation-hardened space systems, FPGA soft cores, boot firmware, and low-power microcontrollers. The language has an official ANS Forth standard (1994), commercial implementations (polyFORTH, SwiftForth), and vibrant open-source ones (Gforth, Mecrisp-Stellaris).

Pros and Cons

If you’re a BASIC user thinking “I should move to C like everyone else,” consider Forth as the road less traveled.

Pros of Forth over C:

  • Interactive REPL like Python – edit, test, run instantly. C requires compile-link-run cycles.
  • Far smaller code size and memory footprint.
  • Blazing development speed for embedded/real-time work. Many Forth programmers claim 2–10× faster productivity than C for hardware-close projects.
  1. Extreme extensibility – you can add new control structures, data types, or even change the syntax.
  2. Built-in assembler and direct hardware access without pointer bugs biting you as often.
  3. The whole system (editor + compiler + OS) lives in RAM with you. You can change anything.

Cons of Forth vs. C - Stack/RPN thinking is weird at first and can lead to “stack spaghetti” if you’re sloppy. - Smaller ecosystem. Fewer libraries, fewer job postings, less Stack Overflow help. - Less portable than C in practice. - Manual memory management is more exposed (no automatic anything). - Community is tiny compared to C.

If you loved BASIC’s immediacy but hated its slowness and lack of power, Forth gives you the best of both worlds: BASIC-level interactivity + C-like performance and control, all in a ridiculously small footprint. You stay in an interactive environment the whole time – no leaving the “interpreter” to compile. With FORTH, you get instant compilation that feels like an interpreter. And, you can add Assembly code natively in the sytsem. Unlike in C, which requires special rules for interfacing with Assembly. With FORTH, it's immediate and direct. For embedded, retro computing, hardware hacking, or just wanting to feel close to the metal without C’s ceremony, Forth is often the more enjoyable and productive choice.

Many people who “graduated” from BASIC in the 1980s went to Forth first (especially on machines like the Jupiter Ace or BBC Micro) and only later touched C – and some never left Forth because it just felt right.

But didn't C "win"?

C “won” over Forth (and many other contemporaries) in the programming landscape of the 1970s and 80s not because it was objectively superior in any technical dimension, but because of a combination of ecosystem momentum, practical engineering trade-offs, institutional adoption, and social/cultural factors that favored C for large-scale, team-based, and cross-platform work.

Many people who loved Forth's immediacy, minimalism, and raw power (especially on constrained 8-bit machines like the Jupiter Ace or BBC Micro extensions) stuck with it for decades, particularly in embedded, real-time, or niche hardware control. But C pulled ahead decisively in the mainstream due to it's connection with UNIX. Unix (and later Linux) were written in C from very early on. C became the de facto strandard earlty on for operating systems, tools, and everything built on top of them. Everything was in C. You “had to” learn C. If you learned something it else it wasn't as important. Some people just bothered to learn C and ignore everything else.

Forth never had an equivalent “killer app” ecosystem that pulled in masses of developers. It stayed more niche (telescope control, industrial automation, some embedded, Open Firmware on PowerPC/SPARC).

Horse of a different color

C has a relatively fixed syntax and semantics protocol (even with preprocessor tricks). C code mostly looks like C. You can read someone else's C code without learning a completely new dialect. This is important when discussing maintainability of code in teams. See: Rob Pike's 5 Rules of Programming.

On the other hand, Forth is extensible to the point of being a meta-language. Every serious Forth project reinvents parts of the language (new control structures, parsing, object systems, etc.). This makes large team collaboration harder. You have to learn the local “dialect” of Forth for each codebase. To be absolutely fair, many C programs essentially define their own language by writing helper functions. But because the interface is so well defined (i.e. header files) it still “looks like C” and can be somewhat excused. FORTH programmers may consider this unfair, but forcing people to implicitly document their code via header files played a huge role in C's adoption. It is ironic that today, header files are considered bad meta.

Written in FORTH

Game Date / Publisher About
Starflight 1986 (EA / Binary Systems) The standout. A huge open-world space RPG with trading, combat, planet landing, and alien diplomacy. Coded mostly in Forth (plus a few x86 assembly routines for speed). It had to fit in just 128 KB of RAM, and Forth’s compactness made that possible. Sold over a million copies, won awards, and is still beloved today. Ports to Amiga, Atari ST, Mac, C64, and even Sega Genesis later.
ChipWits 1984 (BrainWorks) A charming puzzle game where you visually program a little robot to navigate mazes and hazards. Original Mac version used MacFORTH; C64 version used SuperForth 64. The full Forth source code was released in 2024 for its 40th anniversary – perfect for retro hackers to study.
Adventure Construction Set 1984 (Electronic Arts) One of the very first RPG/adventure game makers. You built tile-based worlds, monsters, and quests. Creator Stuart Smith confirmed in a 2020 interview that the entire thing was written in Forth on a Commodore 64.
Lords of Conquest 1986 (Electronic Arts) Strategy/war game, also in Forth.
Amnesia 1986 Text/graphical adventure, one of the seven games officially listed in Wikipedia’s “Video games written in Forth” category.

Several official Atari 7800 console games were developed in Forth as well. It was surprisingly common for quick ports and prototypes. Games like Karateka, Hat Trick, and Worms were written in Forth. Notably the Forth source code for Worms (1983) is available on GitHub.

The original Atari 800 Dig Dug was done in Forth. Professor Pac-Man (1983, Bally/Midway) was written in Forth. The Jupiter Ace, a home computer using FORTH instead of BASIC was released in the UK, and ports of many popular games including PAC MAN ran on the system. Bally and Midway, as well as Atari, often prototyped games in FORTH. The reason why some games are well-known to have been coded in assembly is because FORTH can define assembly routines as functions (words). In a 6502 Forth for example, you always write performance critical parts in assembler, as most Forth systems have an build in 6502 assembler (and if not, it's trivial to add).

RAMBrandt (Antic Software) was written in Forth.

AtariLab was written in Forth. Landon Dyer who worked at Atari said that someone at Atari would often start porting a game in Forth, but then later it would be optimized in assembly due to speed and size concerns of the 2600 and 800–The Atari 800 had a base of 16k RAM and the 800 had, I believe, 128 bytes of RAM– but the games game on cartridges containing 2k to 4k of ROM.

FORTH saw critical commercial success in the business world as well. RapidFile (1986, Ashton-Tate) was a flat-file database manager written in Forth. Ashton-Tate was big in databases back then (dBase III fame), so this reached business users.

The open boot / open firmware on Sun SPARC stations and PowerPC Macs, as well as many embedded systems were written in FORTH. You dropped to an “ok” prompt on boot for diagnostics/config. Millions of machines ran Forth at startup without users knowing. Millions. Forth does have it's legacy to consider!

Learning Curve Estimates

  • BASIC: Can write programs immediately. Easy, linear learning curve.
  • Python: 80 to 90% of BASIC or Lua programmers can be comfortable in under a week.
  • C takes 2 or 3 weeks of pain to get pointers and structs and such, and you get better at it with time over the long run.
  • Java takes 3 to 6 weeks due to it's OOP and verbosity.
  • Forth The learning curve of C or Java compressed into the first week. Most will quit in the first week. But those survivors who make it through the first week often say they began writing real code faster than in C afterward, because there’s so little to learn.

Final thoughts

Bindings for SDL, SDL2, OpenGL and many other vital libraries exist for FORTH – as well as C bindings. In the end, it is a blue sky language, yours to discover. It's not a mature, documented or widespread as C, but the user doesn't care what language the game is written in. “if you write it, they will come.”

sd/star_forth.txt · Last modified: by appledog

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki