Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

You programmed this in Forth? What even is that?

(+1)

Yep! It's an old, stack-based programming language from the 70s. For an example there's a joypad read routine in this file. It's fun, but it definitely isn't the most comfortable language to code in 😅 That said, I think it's still nicer for the programmer than straight 65c816 ASM!

I wrote a compiler (snes-forth) for it targeting the SNES for last year's jam, then upgraded and reused it this year as well :)

That's interesting! What makes a programming language stack-based?

The main thing is that arguments are passed implicitly via a stack rather than as an argument list like in most other languages. For example, in C you might write:

int sumThree(a,b,c) { return a + b + c; }

But in Forth you would write:

: SUM-THREE + + ;

Which defines a new function (called "words" in Forth) that calls the "+" word twice. + takes the top two elements off the stack, adds them, then pushes the result, so doing it twice ("+ +") sums the top three numbers on the stack.

You wind up naming a lot fewer variables because so much state is passed around implicitly, but that also makes it kind of hard to manage and debug 😅 

Do you have to put a b and c in the stack before you call sum-three?

(+1)

Exactly! So the call would look like: 

A B C SUM-THREE

Or using literals like: 

1 2 3 SUM-THREE

Or maybe the first two arguments are already on the stack from a previous function call and you just want to sum them with 5:

5 SUM-THREE

It sounds so complicated. But that's probably because I'm unfamiliar with it

(+1)

The big benefit is that if you're starting from nothing, you can get a usable Forth development setup with a lot less time and effort than it would take to make a compiler for a language like C, and the development tools will use a lot less memory. Was really helpful in the 70s.

That's interesting! A whole world of programming I didn't know about