Tuesday, June 16, 2015

Going Forth on the Commodore 128

Forth is available for most vintage computer platforms; however, no native version exists for the Commodore 128.

I'd like to fix that.

It's surprising to me that a computer like the C128, with lots of RAM, 80 columns, and a 2 MHz-capable processor, never had a Forth implementation. It practically screams for one.

It's a few decades late, but better late than never!

Why Forth?

My first computer language was Fortran, and we had to walk five miles uphill, in the snow (punch cards) to program in it. When I first encountered an interactive system - BASIC on the Apple II - it was like the harps played and sunbeams shot down to Earth.

Once the glamour of immediate feedback wore off, I started to find the lack of named subroutines and spaghetti code in BASIC was a bummer compared to the more structured Fortran, and later Pascal. Something of a compromise would have been cool. Too bad I didn't know about Forth back then.

Forth is an odd bird. Backwards things in it you do. Despite it's quirky nature, it strangely both encourages top-down design while facilitating low-level experimentation. Some have complained the resulting code is write-only (hard to decipher), but if you do it right, it's actually pretty intuitive. Modern programming concepts such as loose coupling, tight cohesion of function, and data encapsulation were features of Forth from the beginning.

And it's fast. Much quicker than BASIC, and it often produces more efficient code than a high level language like C.

So, that's why. Now, how?

  • I've read "Starting Forth" by Leo Brodie to refamiliarize myself with Forth and its internals. Having finished, I'm now starting on "Thinking Forth", the sequel.
  • I've begun reading Forth Dimensions, the newsletter of the Forth Interest Group (FIG) from back in the day. This provides some historical perspective, and includes discussion on architectural choices (e.g., threading models). More on that in later posts.
  • Now is also the time to take another stroll through 6502 programming texts, starting with Lance Leventhal's "6502 Assembly Language Programming".
  • The Commodore 128 has a lot of memory - but it's not trivial to use it from assembly language. Understanding how the bank-switching works has been a bit tough, but I think I'm close to getting it. The book "Mapping the Commodore 128" has been invaluable.
  • I'll need to take full advantage of the VDC - the Commodore 128's awesome 80 column video chip. The Commodore 128 Programmer's Guide is a starting point, and there are other Internet sites where you can read more about the VDC and its wonders.

What Next?

The upcoming Retrochallenge 2015/07 is as good an excuse as any to get my posterior in gear. Hence, I'll be turning in my submission and taking a run at it. The Goal - have a working Forth kernel that accepts some interactive commands and does stuff, native to the C128. It might not be finished, and it might not be bug-free (almost certainly not) - but it will run.

Stay Tuned!


  1. Hi, nice to hear that you are interested in writing a Forth for the C128 :)
    One thought is that you should maybe investigate using the Z80 for your Forth. Z80 instruction set is much better suited for that, than the 8502. As I understood, there should be ways to execute Z80 code also from native C128 mode.

  2. Have you looked into porting a version of Fig-Forth to the native C128 mode?