top of page
Search

Bonus: White Lightning For IF

Writer: Tom GroveTom Grove

My last post argued that White Lightning didn't really make the task of writing arcade games any easier. But maybe writing arcade games is not really Forth's forte - are there are other genre's where the language features of Forth might add enough credit to justify its use?


What about Interactive Fiction? ( IF ) I wrote a collection of Forth words that provide a basic IF engine. A fairly poor one, but one that can run a version of "Cloak of Darkness " ( http://www.firthworks.com/roger/cloak/ ) , the IF's community's "Hello World" . Here's what it looks like:


I feel this is actually quite tidy - the ability to add new compiler words really helps here. The basic underlying idea here is to add enough string support to Forth to allow it to parse a simple Verb-Noun command, convert to a word identifier, look it up from the dictionary and execute it. I.e. If the player enters:

read message

it is parsed into

-READ-MESSAGE

If this exists a corresponding word in dictionary, the word is run. We have location arrays and object arrays and some words for setting these up, which let us support some generic actions. E.g.

-TAKE-TICKET then runs the generic TAKE-* word which takes a pointer to the ticket object and does the usual checks ( the object is present, the player isn't already carrying it ). We handle synonyms by the lazy method of just having another word call this word. Location related commands like "n, look" are constructed by appending the players location to the command. So if the player is in the foyer and types

n

for north. Then the runtime tries to execute the word

-N-THE-FOYER

We can compile the "if engine" separately to make a new Forth base image. If we were doing this in anger we would get rid of IDEAL and probably attempt to move the Forth state variables higher in memory. This would leave the bulk of memory, over 30k, for our game.


A nice feature of Forth is that it runs on its own "VM". This gives it the nice z-machine-like ( https://en.wikipedia.org/wiki/Z-machine ) property of being able to run equally well on a modern PC as on nearly 40 year old hardware:


Anyway, that really is enough Forth. Code for this is here: https://github.com/tomgrove/WhiteLightningBlog/tree/master/Stuff



 
 
 

Recent Posts

See All

Flying Shark : Object Logic

Every object has a type field ( 0x5 ) that selects a tick routine. The tick routine for a bomb power-up is shown below (link to video)....

Comentarios


©2020 by Incoherent Retro Rambling. Proudly created with Wix.com

bottom of page