Vimclair BASIC

Description of the page content

A Sinclair BASIC preprocessor written in VimL

Tags:

Brief description

Vimclair BASIC is two things:

  1. An improved version of Sinclair BASIC.
  2. 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:

  1. The improvements of SAM Coupé's MasterBASIC (a descendant of ZX Spectrum's Beta BASIC): control structures, procs, labels, long variable names…
  2. 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.

README file

Vimclair BASIC is a Sinclair BASIC preprocessor that makes development easier.

Features

  • C-style block and line comments.

  • Bash-style line comments.

  • Labels instead of line numbers.

  • #vim directive to execute any Vim command in the source.

  • Long variable names for strings, arrays and FOR loops, using the #vim directive 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

    • EXIT DO

    • EXIT FOR

    • IF …​ THEN …​ ENDIF

    • IF …​ THEN …​ ELSE …​ ENDIF

    • IF …​ THEN …​ ELSE IF …​ ELSE …​ ENDIF (with any number of ELSE IF)

  • Procedures (without parameters):

    • DEF PROC, END PROC, EXIT PROC, CALL.

  • Procedures with parameters can be simulated ad hoc with the #vim directive.

  • The CALL command can be changed with #procedureCall, e.g.: #procedureCall proc or even make it empty: #procedureCall.

Files

  • README.adoc: This file.

  • LICENSE.txt: The license.

  • vbas2tap.sh: Command line wrapper for the Vimclair BASIC to TAP converter.

The 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.

Requirements

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 #tapmaker directive is used to choose one of them; if the #tapmaker directive is empty or missing, no TAP will be created, but only the BAS file.

BAS2TAP

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.

This is how I compiled and installed BAS2TAP on Raspbian and Debian:

   gcc -Wall -O2 bas2tap.c -o bas2tap -lm
   strip bas2tap
   sudo mv bas2tap /usr/local/bin/

zmakebas

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 FN doesn’t include the required 5 bytes for each parameter. This made FN fail. This bug was fixed by Antonio Villena in his own version: http://sourceforge.net/p/emuscriptoria/code/HEAD/tree/desprot/ZMakeBas.c.

Installation

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 ~/bin/ or /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.

Usage

Vimclair BASIC source files use the VBAS filename extension by default, but you can change it in ~/.vim/ftdetect/vimclairbasic.vim.

Whenever you open a Vimclair BASIC program with Vim, the proper syntax highlighting will be selected, and the normal-mode key map .tap (defined in 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
.

Download

Vimclair BASIC in GitHub.

Related pages

Imbastardizer
A BASIC preprocessor written in Vim.
MBim
Cross-development toolkit for MasterBASIC and SimCoupe.
SBim
An S*BASIC preprocessor.
CE4 [para ZX Spectrum +3e]
[Proyecto:] Juego de aventuras de texto con gráficos, escrito en Vimclair BASIC para ZX Spectrum +3e.
Initial development history of Vimclair BASIC