Pascalated Boriel ZX BASIC
for the ZX SPECTRUM

(No GOTOs, no line numbers)


Tutorial By Example

Lesson Title View Download
the files
Run online Pascalated Boriel
0 Demo (factorial)
1 Guess the Number
2 Laser
3 The Lost Comic Book
4 Multiplication Table
5 Cannonball (Bala)
6 15
7 4 In a Line
8 Pong
9 Worm
10 Predator
11 STRON
12 The Towers of Hanoi
13 Dogfight David
14 Memory (hidden cards)
15 Joker
16 River Crossing
17 Fair Shares
18 Hangman
19 Klotski (big square)
20 Maze Walls (1,2,3)
21 Readline, VAL, 3D Graph z=F(xy)
22 Space 1999 - Eagle 1
23 Space Invader
24 Torpedo
25 The Towering Inferno
26 The Blue Diamond (<^>)

Click here to access the 2024 Pascalated Boriel ZX BASIC Contest

History

1958 - ALGOL 58, the first structured programming language.
1970 - Pascal - the most famous structured language.
1976 - SBASIC (Dartmouth Structured BASIC) - the first attempt to create a structured BASIC.
1981 - BBC Micro - with one of the first structured BASIC.
1983 - Structured programming became widely known with Turbo Pascal 3 from Borland.
1984 - Sinclair QL with structured SuperBASIC.
1985 - QuickBASIC (later QBASIC), the first structured BASIC without line numbers.
1987 - Pascalated BASIC for the ZX Spectrum (in MicroSe7e newspaper, Portugal).
2021 - Pascalated BASIC to ZX Spectrum Converter (javascript).
2023 - Pascalated BASIC compiled with Boriel ZX BASIC Compiler.


Instructions

Main rules of Pascalated Boriel
Do not use line numbers.
Do not use GOTO, RUN, DO, LOOP, EXIT, SUB, GOSUB. And you can use RETURN only on the last line of a function.
Global variables must be declared in the beginning of the program.
Each routine must not have more than 100 lines.
Main routine must be called at the end of the program.
 
Simplest usage of Boriel Compiler
1 - Click HERE to download the compiler (this version includes the file "pascal.h")
2 - Uncompress the ZIP file in a folder or directory of your choice
3 - Write the program on a text file named: Test.bas
4 - Compile the program with the command: ZXBC -taB Test.bas & PAUSE (you can write this command on a BAT file)
      If that doesnt work then see next section.
5 - The compiler generates a TAP file
6 - Open the TAP file on an emulator: Fuse, ZX Spin, Spectaculator, etc.
 
Error: Cannot compile
If the batch file does not work then try this one: PYTHON ZXBC.PY -taB Test.bas & PAUSE
If that does not work then probably you dont have PYTHON installed on your computer.
To install PYTHON follow these steps:
      Open your browser on: www.python.org
      Click on: Downloads
      Click the [Download Python ] button
      Open the downloaded file
      Select this option: [x] Add python.exe to PATH
      Click on: Install Now
 
More info
Study the sintax explained on the table below.
Start by modifying the first demo program listed at the beginning of this page.
Read the demo programs at the beginning of this page.
Read the complete list of reserved words at: https://zxbasic.readthedocs.io/en/latest/identifier/
More info at: https://zxbasic.readthedocs.io/en/latest/syntax/
Forum about the compiler: https://www.boriel.com/forum/forumdisplay.php?fid=11

Sintax

	
	

Pascal

Pascalated Boriel ZX BASIC

Note


		

#include <input.bas>  ' string$ = INPUT(32), number = VAL INPUT(12)
#include <attr.bas>   ' ATTR function
#include <point.bas>  ' POINT function
#include <screen.bas> ' SCREEN$ function

#define PROGRAM   REM
#define BEGIN	  REM
'#define CONST    CONST ' already defined
#define VAR       DIM
#define INTEGER   LONG
#define REAL      FLOAT
#define CHAR      STRING ' UBYTE is type integer
'#define STRING   STRING ' already defined
#define BOOLEAN   UBYTE
#define TYPE      AS
'#define WHILE    WHILE ' already defined
#define REPEAT    DO
#define UNTIL     LOOP UNTIL
#define PROCEDURE SUB
'#define FUNCTION FUNCTION ' already defined
#define TRUNC     INT
#define SQRT      SQR
'#define MOD      MOD   ' already defined
CONST   TRUE      TYPE BOOLEAN = 1 
CONST   FALSE     TYPE BOOLEAN = 0 
		

You must insert these lines at the beginning of the program.

Or, you can put these lines on a file named "pascal.h"
and write the following line at the beginning of your program:
  #include "pascal.h"
		

VAR
  x  :INTEGER;
  y  :REAL;
  z  :STRING;
  ok :BOOLEAN;
  an :ARRAY [0..5] OF INTEGER;
  ax :ARRAY [0..5] OF REAL; 
  Board :ARRAY [0..5] OF STRING; 
		

VAR x  TYPE INTEGER : REM -32768..32767
VAR x2 TYPE INTEGER = 12345 ' with initialization
VAR y  TYPE REAL    ' same as ZX Spectrum numbers
VAR z$ TYPE STRING ' $ is optional - is ignored. 
VAR ok TYPE BOOLEAN
VAR AN(0 TO 5) TYPE INTEGER ' indexes start at 0 instead of 1
VAR AX(5) TYPE REAL 
VAR Board1$(5) ' Indexes are initialized with zero instead of space: a$(1) = CODE 0 
VAR Board2$(0 TO 5) TYPE STRING ' do not use Board$(2,3) to access data
VAR Board3$(8) TYPE STRING ' use Board$(2)(3) to access data
		

Uppercase is different from lowercase.
Other types can be used. Click here for a list of types.
		

REPEAT 
  ...
UNTIL condition; 			
		

REPEAT 
  ...
UNTIL condition			
		

REPEAT loop	
		

WHILE condition DO 
BEGIN 
  ...
END			
		

WHILE condition 
  ...
END WHILE 			
		

WHILE loop
		

IF condition1 THEN
  BEGIN 
  ...
  END			
ELSE IF condition2 THEN
  BEGIN 
  ...
  END			
ELSE
  BEGIN 
  ...
  END			
		

IF condition1 THEN
  ...
ELSEIF condition2 THEN
  ...
ELSE
  ...
END IF
		

IF control structure.
		

PROCEDURE procedure_name;
BEGIN
  ...
END
		

PROCEDURE ProcedureName 
  ...
END PROCEDURE
		

Procedure declaration without arguments.
		

procedure_name(arg)
		

ProcedureName(arg)
		

Procedure call with arguments.
		

FUNCTION function_name (arg:REAL) :REAL;
BEGIN
  ...
  function_name := result
END;  
		

FUNCTION FunctionName (arg TYPE REAL) TYPE REAL
...
RETURN result
END FUNCTION
		

Function declaration with arguments.

Use RETURN only on the last line of a function.
		

t := function_name(arg)
		

t = FunctionName(arg)
		

Function call with arguments.
		

total_apples := 0
		

LET total_apples = 0
total_apples = 0
LET TotalApples = 0
TotalApples = 0
		

Pascal notation 
or Java notation.
		

READ( line );
READ( number );
		

line$ = INPUT(Size)
number = VAL( INPUT(Size) )
		

You must add this line 
at the begining of the program:
  #include <input.bas>
		

Boriel ZX BASIC

Remember: This is not Sinclair ZX BASIC

LET s$ = "0123"
PRINT s$(0)
		
Strings start at position 0.
Sugestion: you can initialize the string with one character 
and the index will be like the ZX Spectrum
but then the LEN will be one extra character.
		
VAR U$(8) TYPE STRING
IF U$(3)(4) = " " THEN PRINT "OK"
		
On the ZX Spectrum, DIM initializes character arrays to " ".
But here, strings on the array must be initialized by the program.
  VAR U$(8) ' On the ZX Spectrum: DIM U$(8,5)
  FOR i=0 TO 7
    LET U$(i+1) = "012345"
  NEXT i
		
VAR v 
		
You should specify the variable TYPE 
because the variable could end up with some undesirable type. 
Example: UBYTE (with values of 0..255).
		
LET s$="012"
PRINT CODE( s$(1) ) - CODE( s$(2) )
		
This prints 255 instead of -1.
You should use PRINT CAST(INTEGER,0) + CODE(s$(1)) - CODE(s$(2))
Forcing INTEGER to REAL:
   LET r = (0.1+a-0.1)/b
or LET r = CAST(REAL,a)/b

Other example:
  PRINT PEEK (0)-255
  PRINT -255+PEEK 0
		
PRINT ''' 123
		
On ZX Spectrum, ' moves to next line.
On the ZX BASIC compiler ' is equal to REM.
You should use: PRINT CHR$(13, 13, 13) ; 123
		
LET A$ = "123"
LET a$ = "456"
Uppercase is different from lowercase.
It's better to use Uppercase for global variables and lowercase for local variables.
		
LET line$ = "123"
		
You can use string identifiers with more than 1 character.
		
LET name$ = "123"
LET name = "123"
		
"$" is ignored - do not use numerical variables and string variables with the same name.
		
Escaped characters
 \\ 
 \* 
 \` 
 \#NNN 
		

The \ backslash symbol.
The (c) Copyright Symbol.
The £ pound sterling symbol.
Any character, where NNN is a decimal number in the range 000 to 255.
		
Block characters
\  \·'\'·\''
\·.\·:\'.\':
\.·\.'\:·\:' 
\..\.:\:.\::
		
Graphic block characters from CHR$(128) to CHR$(143).
		
Control characters.
\{pN}
\{iN}
\{bN}
\{fN}
		
Control characters.
PAPER color 0 to 8.
INK color 0 to 8.
BRIGHT 0 or 1.
FLASH 0 or 1.
		
LET f$ = "4/2*3+2^3"
PRINT VAL( f$ )			
		
Works only with basic operators. 
Sugestion: To use variables create a function VALx$
that substitutes "x" by its value on the entite string. 
Example:
  LET f$ = "2*x"
  LET x = 111
  LET g$ = VALx$( f$ ) : REM g$ = "2*111"
  PRINT VAL(g$) : REM gives 222
Sugestion: To use functions create a function VALf$
that substitutes function name to its code. 
Example:
  LET f$ = "SIN 1.7"
  LET g$ = VALf$( f$ ) : REM g$ = CHR$ 178 + "1.7"
  PRINT VAL(g$) : REM gives 0.99166481
		  
NEW
		
Does not exist.
Use: RANDOMIZE USR 0
		

Aditional info

Recommended utilities
Editor: Notepad (or Visual Studio Code)
Compiler: Boriel ZX BASIC 1.17.3 (or above)
Sprites UDG: https://arcalusitana.org/MuseuZX/ZXspritesUDG
Sprites Block: https://arcalusitana.org/MuseuZX/ZXspritesBlock
Screen: An image editor and BMP2SCR_EXP_2.11a (or ZXPaintbrush for advanced programmers)
TAP editor: BASinC (Tools/TapeEditor)
Testing emulator: Fuse, ZXSpin, etc.
 
Remember
Modify the first program at the beginning of this page and try to compile it.
Study the programs listed at the beginning of this page.
Contact email concurso@ArcaLusitana.org.

Handwritten Pascalated BASIC (c) 1987 by ZarSoft
Pascalated BASIC Converter (c) 2021 by ZarSoft
Compiled Boriel Pascalated BASIC (c) 2023 by ZarSoft
Email: info@ArcaLusitana.org