Dr. Scott M. Baker Enlists Anthropic's Claude AI to Help Write a Forth Program for a Vintage Micro

AI-assisted programming, using large language models, isn't just for modern machines — though getting a working result takes effort.

Vintage computing enthusiast Dr. Scott M. Baker has had a little help with his latest project, writing a Forth-based version of Mary Had a Little Lamb for a Texas Instruments TM990 microcomputer: Anthropic's Claude large language model (LLM).

"I've been working on a new project for a TM990 computer, and I built an AY-3-8910 sound generator board for it," Baker explains. "My TM990 has a FIG-Forth that will run on it, so I figured I would write a music player in Forth. But this time, rather than write it myself, I will enlist my trusty AI [Artificial Intelligence] assistant, Claude-3.5-sonnet on a website called Poe that lets you easily try out AI algorithms. I started with a simple prompt: 'write a forth program to play Mary Had a Little Lamb on a AY-3-8910 sound chip'. Within a few seconds, Claude responded."

LLM-backed chatbots assisting with programming tasks are hot topics right now, but they're not only usable for modern languages. (📹: Dr. Scott. M. Baker)

As anyone who has experimented with large language models (LLMs) will expect, Claude's response was definitely answer-shaped — impressively so, given the likely paucity of Forth-based software sources in the training data ingested by Anthropic to create the model. "Claude made some assumptions about my hardware that didn’t match reality," Baker found, which required a bit of back-and-forth to resolve the issues — starting with creating a replacement for an assumed-present but missing "ms" word for the delay between notes.

What followed was a series of refinements, in which the Claude chatbot "apologised" each time a correction or revision was required — even if the revision was not part of the original prompt, such as making sure the program was compatible with FIG-Forth. At each step, a careful expert eye was required to spot areas where the program was subtly incorrect — such as using the wrong register numbers or calculating the timing incorrectly in such a way as to slow the song down to one-twentieth its original speed, the fix for which then delivered pitches one-third the frequency expected.

Those errors began to increase, Baker found. "Suffice it to say we're getting less right than more right," he noted after a "fix" which required a calculation that exceeded the 16-bit capabilities of the Texas Instruments TMS9900 CPU at the heart of the TM990. Eventually, though, Baker succeeded in prodding Claude to the correct output: a working program, written in FIG-Forth, which makes the TM990 play Mary Had a Little Lamb through a soundcard add-on.

Baker's full write-up, including the source code for the finished program, is available on his website.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles