Description of the page content
A Sinclair BASIC preprocessor written in VimL
Vimclair BASIC is two things:
- An improved version of Sinclair BASIC.
- A program, written in VimL, the programming language of Vim, that converts a Vimclair BASIC source file to a TAP file with its Sinclair BASIC equivalent.
Actually, Vimclair BASIC is just a Sinclair BASIC preprocessor — but it looks, feels and works like a different, say modern, language, to some extent.
Motivation and goal
In summer 2014 I had the idea to start a new project in Sinclair BASIC for the ZX Spectrum +3e, but I missed two things:
- The improvements of SAM Coupé's MasterBASIC (a descendant of ZX Spectrum's Beta BASIC): control structures, procs, labels, long variable names…
- The Vim editor. Vim has been my main work tool for many years. I can not imagine writing code, in any language, without the endless power of Vim.
I investigated and tried all the available tools that convert Sinclair BASIC from plain text files to actual emulator files, but no-one was exactly what I needed, so finally I decided to write my own tool, based on previous related works of mine (BBim, MBim and SBim).
I have been writting my project in Vimclair BASIC for the ZX Spectrum +3e along with Vimclair BASIC itself, so the preprocessor has been tested during the development.
Vimclair BASIC is not finished yet. There are some pending fixes and new features. But it works fine enough to be used for real projects.
Vimclair BASIC is a Sinclair BASIC preprocessor that makes development easier.
C-style block and line comments.
Bash-style line comments.
Labels instead of line numbers.
#vimdirective to execute any Vim command in the source.
Long variable names for strings, arrays and
FORloops, using the
#vimdirective to make the substitutions.
Control structures (can be nested):
DO … LOOP
DO … LOOP UNTIL
DO … LOOP WHILE
DO UNTIL… LOOP
DO UNTIL … LOOP UNTIL
DO UNTIL … LOOP WHILE
DO WHILE … LOOP
DO WHILE … LOOP UNTIL
DO WHILE … LOOP WHILE
IF … THEN … ENDIF
IF … THEN … ELSE … ENDIF
IF … THEN … ELSE IF … ELSE … ENDIF(with any number of
Procedures (without parameters):
Procedures with parameters can be simulated ad hoc with the
CALLcommand can be changed with
#procedureCall procor even make it empty:
README.adoc: This file.
LICENSE.txt: The license.
vbas2tap.sh: Command line wrapper for the Vimclair BASIC to TAP converter.
vim/directory contains Vim specific files:
vim/vbas2tap.vim: Vimclair BASIC to TAP converter.
vim/ftdetect/vimclairbasic.vim: filetype detect (how Vim knows, by the filename extension, that you are opening a Vimclair BASIC source file).
vim/ftplugin/vimclairbasic.vim: filetype plugin (configuration and editing preferences for Vimclair BASIC source files).
vim/syntax/vimclairbasic.vim: syntax highlighting file.
The preprocessing of the source is done by Vim, so it must be installed in the system, even if other editor is used to edit the sources.
In order to convert the sources to a TAP file, Vimclair BASIC needs either BAS2TAP (by Martijn van der Heide) or zmakebas (by Russel Marks). The
#tapmakerdirective is used to choose one of them; if the
#tapmakerdirective is empty or missing, no TAP will be created, but only the BAS file.
At the time of writing (2016-11), its latest version (v2.6, release 2013-01-20), can be obtained from the utilities section of World of Spectrum.gcc -Wall -O2 bas2tap.c -o bas2tap -lm strip bas2tap sudo mv bas2tap /usr/local/bin/
At the time of writing (2015-03), its latest version (1.2, release 2004) is a package of Debian, Raspbian, Ubuntu and probably other distros. Also the sources are easy to find (example: https://github.com/catseye/zmakebas).
The original code had a bug: The tokenization of
DEF FNdoesn’t include the required 5 bytes for each parameter. This made
FNfail. This bug was fixed by Antonio Villena in his own version: http://sourceforge.net/p/emuscriptoria/code/HEAD/tree/desprot/ZMakeBas.c.
Extract the contents of the tar file:tar xvz vimclair_basic.tar.gz
Enter the new directory:cd vimclair_basic
Copy the content of the
vim/directory into your
~/.vim/directory:cp -r vim/* ~/.vim
Create a link to
vbas2tap.sh, with your command name of choice (e.g.
vbas2tap), into a directory in your path (usually
/usr/local/bin/):ln -s vbas2tap.sh ~/bin/vbas2tap
If you prefer the system-wide
/usr/local/bin/directory:sudo ln -s vbas2tap.sh /usr/local/bin/vbas2tap
In the examples above, symbolic links are used. You can create hard links instead, copy or even move the file.
Vimclair BASIC source files use the VBAS filename extension by default, but you can change it in
Whenever you open a Vimclair BASIC program with Vim, the proper syntax highlighting will be selected, and the normal-mode key map
vim/ftplugin/vimclairbasic.vim) will convert your source to a TAP file.
You can use also the command line converter from your OS shell:vbas2tap program.vbas