Boriel ZX Basic Compiler

Authors

Publication

Pub Details

Date

Pages

See all articles from ZXzine Issue 7

I’ve known about the Boriel ZX Basic Compiler for a number of years, but I thought I would give it a try myself. It is designed for creating programs on the Spectrum, but it could be adapted to other computers.

To test it out, I decided to use my one dimensional celluar automata program that I’ve been writing for different computers in different languages. The Spectrum version was designed to run with zmakebas. zmakebas just converts a test file, in Spectrum Basic, to a tap file that the Spectrum will understand. The Basic is the same as the Spectrum.

I was thinking that the Boriel compiler would be the same, but it is not. It will not take an existing Spectrum Basic program and compile it. The compiler as its own Basic syntax, similar to Spectrum Basic, but different enough. This may work well when writing from scratch for the compiler, but not so much when trying to compile an existing program.

I read the documentation on the syntax that the Boriel compiler uses and started modifying my program to fit that syntax. I found that the standard Spectrum IF statement will not work. Boriel’s IF statement must have an END IF. I had to go through my program and change the IF statements. I kept the same flow control, but with an IF statement that supports multiple statements, I could have changed my program to take advantage of that structure.

All variables must be declared as in C and Pascal. Not doing so can really goof up a program. I had one undeclared variable that I was using in a FOR NEXT loop. The loop kept going beyond the ending number. I was going from 7 to 0 STEP -1. The loop kept going below 9 to a much higher number. I noticed that I had not declared the variable, declared it and then the loop just worked.

The INPUT command is far different that the one for Sinclair Basic. Instead of it being like this:

INPUT a$ 

The syntax is this:

a$ = INPUT(20)

This allows for the user to type in a string of up to 20 characters. I had to dig in the documentation for that one. The full syntax of the language is on a number of pages on the Boriel Wiki. The input is also on the main part of the screen, and not down at line 23, as in Spectrum Basic.

I also found out that if using the variable a$, the compiler complained if you also used the variable a as an integer variable.

After I was able to adapt my program to the Boriel syntax, it compiled fine and it created a .tap file. I loaded it into EightyOne and the program ran very fast.

One thing that I was wondering, was if the compiler could create a program that would run on the T/S 2068. I created a simple program:

print "x"

then compiled it and tried it on the T/S 2068 in EightyOne. It ran fine. The issue will be when using a command that will need a Spectrum ROM call to execute. The compiler has a library of Z80 assembly instructions that it uses. It should be possible to find all of the Spectrum ROM calls and replace them with T/S 2068 ROM calls. I think this is something that I might look into.

If one is writing just for the Boriel zx compiler, the syntax does go beyond what ZX Basic does. The Boriel compiler is based on FreeBasic, so that is one source for idea how the syntax of the language works. One of the best features is that Boriel allows for IF statements that support multiple lines and also supports ELSE. In ZX Basic, the IF statement is like this:

IF x = 0 THEN print x: print y: print z

Now this can look a little clustered. I’ve never liked using multiple commands in a single line. Here is the same in Boriel:

IF x = 0 THEN 
  print x
  print y
  print z
END IF

The language also supports ELSE and ELSE IF in the same way that SuperBasic does.

Another flow control command is WHILE … WEND. The WHILE is used like this:

WHILE x = 1 
....
....
WEND

Another flow control set is DO …. UNTIL. The WHILE does a check at the start of the loop, DO … UNTIL does the check at the end. It works like this:

DO 
....
....
UNTIL x = 1

Each has their own use case. In classical flow control documentation, a DO .. UNTIL is the same as a DO .. WHILE. The WHILE.. WEND is also a WHILE.. DO loop.

Boriel compiler does have a reserved word list on its Wiki. This is a great resource for discovering the syntax of the language and what commands are different in Boriel versus ZX Basic.

For those programmers not wanting to get into C (with Z88dk) or assembly, the Boriel compiler is a great way to get speed and still work in Basic.

Products

 

Media

 

Image Gallery

Source Code

Scroll to Top