This week I have been looking at bygone computers and some of the languages they used - tailored to work within the framework of their resource limited hardware.
My recent dealings with the "Forth-like" SIMPL language has led me to look for other examples of minimalist programming languages. Many of these were devised in the 1970s and 1980s - when home microcomputers were very short of memory resources.
In this post I look at some very small computer languages - often less than 4Kbytes in size.
My recent search has unearthed the following:
VTL Very Tiny Language - a BASIC like language for resource limited microcontrollers
VTL-2 An updated VTL with more features - yet assembles in 768 bytes
Mouse - developed in the late 1970s for electronic music applications on a PDP8
TinyForth - A cut down Forth, written in C or assembler
Txtzyme - an I/O oriented minimal control script with some Forth-like features
SIMPL - an extended version of Txtzyme to run on several platforms.
TinyBasic - various offerings available. TinyBasicPlus
Bitlash - a control oriented, Programmable Command Shell to run on Arduino
VTL is an interpreter designed in 1977 by Frank McCoy for the 6800 and 8080 machines of that era. The complete 6800 version of his interpreter is ROMable, IN 768 BYTES!
VTL was originally devised for the Altair 680 - an early 6800 microcomputer, with a strong similarity to it's stablemate the MITS Altair 8800 but much smaller in size. It had 1K of RAM and sockets to accept 1K of ROM. ROM chips at this time were likely to be only 256 bytes - so 4 sockets required!
There appears to be a following for VTL and its derivatives in Japan - so many of the references are Japanese websites - but easily translates with Google Translate.
Summary of VTL languages over the years - translate from Japanese
"Creating a VTL Language" Some description of VTL for 6800, 8080/Z80 and AVR - source code in assembler and C - Translate from Japanese. This site and source code provided by T. Nakagawa.
The author, T. Nakagawa, has provided source code (about 370 lines - see this Github Gist) that will run on an Arduino with a bit of fiddling. You will need to add the serial putchr and getchr routines to drive the UAR - and include the UART code from AVR-Lib.
Once these are added, it compiles to about 2.6K under the Arduino IDE. It should be noted that the AVR uses a 16 bit instruction word - so the byte count for AVR Flash code is generally about twice that of other 8 bit microcontrollers.
If you want to try out VTL - this is a packaged exe that runs on a PC in a command prompt window.
VTL remains of interest because it has some very compact C code for the various building blocks of a simple interpreter - and is relatively easy to understand its operation.
In 2007, some thirty years after his original VTL offering, Frank McCoy revisited his VTL and produced an extended and improved version of VTL - which still fits into 768 bytes (on 6800) The User Manual and some example programs are here.
Mouse is a very small language that was written in the late 1970s - early 1980s by Peter Grogono.
It was a further development of his early 1970s system/language MUSYS - that was written to aid his work with early computer generated electronic music on resource limited PDP-8 machines.
Mouse took aspects of MUSYS and updated them to suit the late 1970s emerging microprocessor scene.
Here are some links:
The Mouse Programming Language
The Great Mouse Programming Language Revival
Wikipedia has further links that may be of interest.
This site and source code is again provided by T. Nakagawa, a Japanese enthusiast of Tiny languages.
He has written TinyForth both in well commented AVR assembly language (1964 bytes) and also in C that closely follows the assembly language. This not only gives a good illustration of how the language has been constructed but also how closely AVR assembly is matched to C.
I have created a Github Gist for this TinyForth - complete with UART getchr and putchr routines. The code compiles to 4854 bytes - I used Arduino 1.04 IDE - as I had some difficulty with later versions with getting the UART code to compile.
It appears to be a subset of Forth - but with sufficient keywords currently available to do simple tasks - but like any Forth is easily extended.
Input and Output is via a serial UART interface only - it would need further extensions to the dictionary to build up a vocabulary of I/O and timing functions for the Arduino/AVR.
The AVR assembly language version is much more compact - I have added a fully commented version to this Github Gist
If you want to write a Tiny Forth for an AVR or even an ARM - then this is a good place to study the basic language structure.
In conclusion - TinyForth looks like it could provide a useful kernel for a larger project. It would be worth compiling this source for an ATmega1284 - the extra RAM (16K) and additional I/O port would make a very capable Forth Computer.
As a newcomer to AVR assembly (but having done a lot of Z80 years ago) it is rewarding to see how readily C code can be translated to assembly language. A lot of the Forth primitive wordss are of immediate use for the Txtzyme/SIMPL interpreter (see below) - and having the C and assembler code together is a useful crib on how one might take the project forwards further.
Txtzyme was created around 2010-2012 by Ward Cunningham. Txtzyme has the advantage that it is specifically oriented to I/O control and interaction - yet surprisingly simple.
The Arduino version allows simple control of the Arduino I/O and allows timing functions and loops. LED sequences, musical tone generation and printing serial output of analogue sensors are easily performed.
It is simple in nature - essentially just a single character interpreter contained within a loop. It uses a single stack variable x to control some parameter of the operation. It is fairly simple to understand and easily extendable to include further "words" such as arithmetical and logical functions.
The Arduino version is just 90 lines of code and compiles to 3518 bytes. The codesize can be much reduced by replacing some of the Arduino C functions with more compact code, possibly even resorting to AVR assembly language in order to make a more compact kernel.
The beauty of Txtzyme is it's simplicity and the fact that it can be easily tailored to suit a particular application.
Reducing the Code Size:
Removal and replacement of the Arduino Serial code and using a custom function to print a long number can bring this down to 1884 bytes.
Removal of the Setup() and loop() functions and replacing with a main() and a while(1) will reduce it to 1782 bytes - but at a loss of the timing delays and millis() functions
Removal and replacement of the Arduino delay and delay_microseconds code will bring it down to
Replacing digitalWrite with a simplified function - reduces it to 1040 bytes
Removal of analogRead and digitalRead reduces it by a further 92 bytes to 948 bytes.
digitalRead alone is 272 bytes!
If you want to try a cut down version of Txtzyme - I have paired out most of the bloat and put a 658 byte minimum kernel here. It doesn't do much - you have to add your own functionality in the form of case statements.
Txtzyme appears to indicate that a I/O oriented micro language is possible on the AVR (Arduino) in about 1024 bytes. This makes it possible to include it with a bootloader plus some extensions in under 2K.
The code-shrunk version of Txtzyme is available on this Github Gist You may wish to re-instate digitalRead (line 110) and analogRead (line 150) depending on your requirements.
In the next post I look at SIMPL and how it has evolved from Txtzyme.