ZXBasic

From BorielWiki

Jump to: navigation, search

Contents

Introduction

ZX BASIC is a BASIC cross compiler. It will compile BASIC programs (in your PC) for your ZX Spectrum! (other platforms might appear in the future). ZX BASIC is an SDK entirely written in python. It consist in 3 main tools and some libraries you might also find useful (see below).

Installation of ZX Basic SDK

ZX Basic SDK comes in two flavours:

  • Multiplatform (Linux / Windows / Mac) python scripts. This is the main distribution and recommended for everyone.
  • Windows .MSI Installer.

The latest is only for Windows users who are not able or very lazy to use python scripts directly. This .MSI distrubution is not updated as often as the Multiplatform one, but has the advantage of not requiring the python interpreter previously installed.

Prerequisites

For the Multiplaform bundle, you will need the python interpreter version 2.5 or higher installed on your system (Linux users will probably have it already installed since it is very common on that OS). For Windows users, there's also a python interpreter from ActiveState, the ActivePython interpreter, 100% python compatible.

On the other hand, Windows users who choose the .MSI installer distribution does not need to install the python interpreter.

Downloading

To get the latest version of the ZX BASIC SDK, go to the Download Page, and get the .MSI or .ZIP file you want. The .ZIP files are Multiplatform (Linux / Windows / Mac) whilst the .MSI files are for Windows only, as previously explained.

Installing

Installing the .MSI distribution is pretty straighforward: Just double-click on the .MSI file once downloaded. You can later uninstall it by going to your Add/Remove Programs section in your Control Panel.

The .ZIP distribution does not require any installation. Just uncompress the SDK tree in a directory of your choice and make sure that folder is included in your PATH environment variable.

Warning: Do not use the SDK folders to place your source code.

This applies for both .MSI and .ZIP packages. If you mix your .bas code with the one in the SDK you can end messing up your installation. Keep your computer tidy! Use your *own* folders to create your BASIC programs. This will also prevent upgrade problems in your SDK.

Testing your installation

For the .ZIP distribution, type zxb.py. For the .MSI windows version, type zxb You should see something like:

>zxb.py
Usage: zxb.py <input file> [options]

zxb.py: error: missing input file. (Try -h)

Ok, the compiler is working (or it seems so). Now you should proceed to the following section to learn about its usage.

The ZX BASIC SDK

As you might already know, ZX BASIC is not a single program. It consist in 3 python (.py) programs that might be used standalone or not, depending on how they are invoked.

ZXB

ZXb is the main compiler executable (for Windows you can use the .exe converted version). It will compile a BASIC program into a binary file. At this moment, supported binary formats are: TZX, TAP and raw binary (.BIN) format.

Go to the zxb page for help on using the compiler.

ZXBasm

ZXbasm is a cross-platform Z80 assembler. It will assemble plain ASCII files containing asm source code into the same formats described above. This tool is completely finished.

Go to the zxbasm page for help on using the assembler.

ZXBpp

The zxbpp utility is a preprocessor which works in the same way as many C preprocessors (cpp) programs do. It is used both by zxb and zxbasmp. It basically filter an input file and produces a modified output one, by replacing macros and include files. If your used to C preprocessors (e.g. you've used Z88Dk), you will probably be very familiar with it.

Go to the zxbpp page for help on using the preprocessor.

Language Reference

The Reference contains all the information about the ZX BASIC (not Sinclair BASIC) language: The syntax, reserved words, control-flow instructions, function declarations, etc.

Whenever you read the term ZX BASIC it refers to the BASIC language variant this compiler understands. ZX Spectrum original (legacy) BASIC is referred here as Sinclair BASIC.

Go to the Language Reference page for more information.

Tutorials

Tutorials and examples are the fastest way (in my opinion) to learn a new language. Well, ZX BASIC is not so new if you are used to Sinclair BASIC. The following is a list of examples, some of them already bundled with the ZX BASIC distribution in the examples/ directory:

Draws a circle pixel by pixel using PLOT primitive
Sample clock which uses the FRAMES variable (taken from the ZX Spectrum 48K user manual)
Like above, but a bit improved.
Colors example from the ZX Spectrum user Manual
Random color lines example from the ZX Spectrum 48K user manual.
Factorial recursive test.
A sound demo (taken from the ZX Spectrum 48K user manual)
UK Flag drawing (taken from the ZX Spectrum 48K / 128K user manual)

Games

The snake game by Federico J. Alvarez Valero (05-02-2003) (English version)
Personal tools