Sinclair BASIC
Paradigm | Imperative |
---|---|
Developer | Nine Tiles Networks, Sinclair |
First appeared | 1979 |
Platform | ZX80, ZX81, ZX Spectrum |
License | Proprietary |
Sinclair BASIC is a dialect of the BASIC programming language used in the 8-bit home computers from Sinclair Research and Timex Sinclair. The Sinclair BASIC interpreter was made by Nine Tiles Networks Ltd.[1]
Contents
History
Sinclair BASIC was originally developed in 1979 to fit in the 4 KB of ROM available on the Sinclair ZX80.
It was initially an incomplete implementation of the 1978 ANSI minimal BASIC standard, and evolved through the 8 KB ROM ZX81 and TS1000 to be an almost complete version in the 16 KB ROM ZX Spectrum. It is present in all ZX Spectrum compatibles.
Currently, interpreters exist for modern operating systems (as well as for vintage systems) that allow Sinclair Basic to be easily used.
Syntax
Reserved words
On the ZX Spectrum, there are 88 reserved words in Sinclair BASIC, denoting commands (of which there were 51), functions (32), and other keywords (5):
- Commands
BEEP
,BIN
,BORDER
,BRIGHT
,[note 1]CAT
,[note 2]CIRCLE
,CLEAR
,CLOSE#
,[note 2]CLS
,CONTINUE
,COPY
,DATA
,DEF FN
,DIM
,DRAW
,ERASE
,[note 2]FLASH
,[note 1]FORMAT
,[note 2]FOR
,[note 3]GO SUB
,GO TO
,IF
,[note 4]INK
,[note 1]INPUT
,INVERSE
,[note 1]LET
,[note 5]LIST
,LLIST
,LOAD
,LPRINT
,MERGE
,MOVE
,[note 2]NEW
,NEXT
,OPEN#
,[note 2]OUT
,OVER
,[note 1]PAPER
,[note 1]PAUSE
,PLOT
,POKE
,PRINT
,RANDOMIZE
,READ
,REM
,RESTORE
,RETURN
,RUN
,SAVE
,STOP
,VERIFY
- Functions
ABS
,ACS
,AND
,[note 6]ASN
,ATN
,ATTR
,CHR$
,[note 7]CODE
,[note 7]COS
,EXP
,FN
,INKEY$
,[note 7]INT
,IN
,LEN
,LN
,NOT
,[note 6]OR
,[note 6]PEEK
,PI
,POINT
,RND
,SCREEN$
,[note 7]SGN
,SIN
,SQR
,STR$
,[note 7]TAN
,TO
,USR
,[note 8]VAL$
,[note 7]VAL
,[note 7][note 9]- Other keywords
AT
,LINE
,STEP
,TAB
,THEN
[note 4]
They are entered via Sinclair's somewhat unorthodox keyword entry system. The most common commands require just a single keystroke; for example, pressing P causes the entire command PRINT
to appear. Less frequent commands require more complex key sequences: BEEP
(for example) is keyed by pressing CAPS SHIFT plus SYMBOL SHIFT to access extended mode (later models include an EXTENDED MODE key), keeping SYMBOL SHIFT held down and pressing Z. Keywords are colour-coded on the keyboard to indicate which ⇧ Shift-sequence is required.
Commands found exclusively on the ZX81 and its clones, the TS1000 and TS1500 are FAST
, SCROLL
, SLOW
, UNPLOT
, GOSUB
and GOTO
(vs the Spectrum's functionally identical GO SUB
, GO TO
).
On the ZX Spectrum each reserved word was assigned a character code between 165 and 255 in the latter half of the system character set, and expanded by referencing a token table held in ROM. As a result, any reserved word in a program listing occupied just one byte of memory, a significant saving over traditional letter-by-letter storage. This also meant that the BASIC interpreter could quickly determine any command or function by evaluating a single byte.
The 128k Spectrum models—the ZX Spectrum 128, +2, +3, +2A, and +2B—introduced a conventional letter-by-letter BASIC input system, and two new commands, neither of which was present in or recognised by the machine's legacy version of 48k BASIC:
PLAY
, which operated the 128k models' AY-3-8910 music chipSPECTRUM
, which switched the 128k Spectrum into a 48k Spectrum compatibility mode
The original Spanish ZX Spectrum 128 included four additional commands in Spanish,[2] one of which was undocumented. These can be translated as:
EDIT
(to edit a line number or invoke the full screen string editor)RENUM
(to renumber the program lines)DELETE
(to delete program lines)WIDTH
(to set the column width of the RS232 device, but undocumented as the code was broken)
Unlike the LEFT$()
, MID$()
and RIGHT$()
functions used in the ubiquitous Microsoft BASIC dialects for home computers, parts of strings in Sinclair BASIC are accessed by numeric range. For example, A$ (5 TO 10)
will give a substring starting with the 5th and ending with the 10th character of A$
. As with modern programming languages such as Python, it was therefore possible to replace the LEFT$()
and RIGHT$()
commands simply by omitting the left or right array position respectively; for instance A$ ( TO 5)
is equivalent to LEFT$(A$,5)
.
Versions
48 BASIC
48 BASIC is the common name of the original Basic present on the ZX Spectrum computer (and clones).[3]
128 BASIC
128 BASIC is the common name of the version present on the ZX Spectrum 128.[4] It offers extra command and standard letter by letter input.
+3 BASIC
+3 BASIC is the common name of the Basic present on the ZX Spectrum +3.[3] It offers extra command and standard letter by letter input.
T/S 2000 BASIC
The BASIC dialect used on the Spectrum-compatible TS2068 has the following six keywords as well as the ordinary Sinclair BASIC ones:
DELETE
deletes BASIC program line ranges. ⇧ Shift+0 with theK
cursor produces the commandDELETE
.FREE
is a function that gives the amount of free RAM.PRINT FREE
will show how much RAM is free.ON ERR
is an error-handling function mostly used asON ERR GO TO
orON ERR CONT
.RESET
can be used to reset the behaviour ofON ERR
. It was also intended to reset peripherals.SOUND
controls the AY-3-8192 sound chip.STICK
is a function that gives the position of the internal joystick (Timex Sinclair 2090).
Zebra Systems in New York released a cartridge called ZebraOS, a version of T/S 2000 BASIC that used the 512x192 screen mode.
BASIC64
Timex of Portugal released a software extension called BASIC64[5] to allow better Basic programming with the advanced 512x192 graphic mode available only on Timex 2000 series computers.
This extension added commands and do a complete memory remap to avoid the system to overwrite the extended screen memory area. Two versions existed: a version for TC2048 and a version for TS/TC2068 because they have different memory map.
Other interpreters
For the ZX Spectrum computer family
- Integer BASIC by John Grant - 4K integer version for ZX80
- Floating point added by Steve Vickers - 8K version for ZX81
- Colour and more peripherals added by Steve Vickers and John Grant - unfinished 16K version for ZX Spectrum
- Sea Change ROM by Steve Vickers and Ian Logan, modified by Geoff Wearmouth - finished version for ZX Spectrum
For other machines
- ROMU6 by Cesar and Juan Hernandez - MSX
- Spectrum 48 by Whitby Computers - Commodore 64
- Sinbas by Pavel Napravnik - MS-DOS
- Basic by Philip Kendall - Unix
- BASin by Paul Dunn - Windows
- SpecBAS by Paul Dunn - Windows, Linux, Pandora and Raspberry Pi
Compilers[6]
- HiSoft BASIC
- HiSoft Colt
- Laser
- Softek Floating Point
- Zip Compiler
Other derivatives and successors
For the ZX Spectrum computer family
- Beta BASIC, written by Dr. Andy Wright, was originally a BASIC extension, but ended up as a full-fledged interpreter.
- YS MegaBasic, written by Mike Leaman.[6]
- HiSoft BASIC[7]
- OpenSE BASIC, published in 2011 by Andrew Owen [8]
- Gosh Wonderful, by Geoff Wearmouth, a replacement ROM that fixes the bugs and adds a tokenizer, stream lister, delete and renumber commands.[6][9]
- ZebraOS, a version of T/S 2000 BASIC that used the 512x192 screen mode.
- BASIC64 also enabled 512x192 in Timex machines.
For other machines
- SuperBASIC, a much more advanced BASIC dialect, was introduced with the Sinclair QL personal computer, with some similarities to the earlier Sinclair BASICs.
- BINSIC is a reimplementation of BASIC in Groovy, closely modelled on Sinclair ZX81 BASIC.[10]
- SAM Basic, used with SAM Coupé
- BASin, by Paul Dunn[disambiguation needed], a complete Sinclair BASIC IDE that runs in Windows[6]
Notes
- ^ a b c d e f
INK
,PAPER
,FLASH
,BRIGHT
,OVER
andINVERSE
set attributes for outputting text and graphics to the screen. They can be used either as commands, to apply to all subsequent output until set again, or within aPRINT
statement, to apply only from that point until the end of the statement. - ^ a b c d e f CAT, ERASE, FORMAT and MOVE were originally designed to be used with peripherals, but at the launch of ZX Spectrum, they had not been completely implemented, such that their use generated an error message (Invalid Stream). Later with the aid of the ZX Interface 1 shadow ROM, they were used for the ZX Microdrive. (The shadow ROM was paged when the BASIC interpreter detected a syntax error, which is why most ZX Microdrive commands use a
"*"
). - ^ The control variable of a
FOR
loop must consist of only one alphabetical character. - ^ a b Unlike most other BASIC dialects, Sinclair Basic did not include the
ELSE
operator in theIF
–THEN
(–ELSE
) clause. Thus, instead of:10 IF V=5 THEN GO TO 50 ELSE GO TO 100
it is:
10 IF V=5 THEN GO TO 50 20 GO TO 100
- ^
LET
is compulsory (i.e.,LET A=1
but neverA=1
). This practice is also different from most other BASIC dialects. - ^ a b c The AND, NOT, and OR functions are logical operators.
- ^ a b c d e f g String variable names must consist of only one alphabetical character. Thus,
LET A=5
,LET Apples=5
, andLET A$="Hello"
are all good, whileLET APPLES$="Fruit"
is not. - ^ Machine code could be executed using the
USR
function, the value provided being the start address of the machine code to execute and the return value being the contents of the BC register pair (unlike most other Z80 based computers that returned the value of the HL register pair). thus:LET A=USR 30000
would jump to and begin executing the machine code starting at memory address 30000, and on successful completion would store the value of the BC register pair into the variable A which can then be used by the programmer.
- ^ The
VAL
function does not just evaluate numbers, but also evaluates full expressions. For example,PRINT VAL(A$)
will output 14 when given anA$
of "3*3+4+COS(0)"
.VAL$
does the same but returns a string.
References
- ^ Garfield, Simon (2010-02-28). "Sir Clive Sinclair: "I don't use a computer at all"". The Guardian (Guardian Media Group). Retrieved 2011-05-23.
He is keen to credit [...], not least Nine Tiles, the company that made the Basic operating software.
- ^ Spectrum 128 ROM Disassembly - Spanish Spectrum 128
- ^ a b http://www.worldofspectrum.org/ZXSpectrum128+3Manual/chapter7.html
- ^ http://www.worldofspectrum.org/ZXSpectrum128Manual/sp128p06.html
- ^ http://timex.comboios.info/tmxtechb64-2048.html
- ^ a b c d http://www.worldofspectrum.org/sinclairbasic/
- ^ http://www.worldofspectrum.org/infoseek.cgi?regexp=^HiSoft+BASIC$&pub=^HiSoft$&loadpics=3
- ^ http://sourceforge.net/projects/sebasic/
- ^ http://www.wearmouth.demon.co.uk/
- ^ http://cartesianproduct.wordpress.com/binsic-is-not-sinclair-instruction-code/
Bibliography
- Vickers, Steven (1982). Sinclar ZX Spectrum BASIC Programming. Sinclair Research.
- Ardley, Neil (1984). Sinclair ZX Spectrum+ User Guide. Dorling Kindersley in association with Sinclair Research. ISBN 0-86318-080-9.
External links
- Sinclair ZX Spectrum BASIC Programming: The original 1982 manual by Steven Vickers (referenced above)
- Sinclair ZX81 Basic Programming: also by Vickers
- The History of Sinclair BASIC: By Andrew Owen
- Timex Computer World: Basic 64 user manual for Timex Computer 2048